Code Monkey home page Code Monkey logo

mina.net's People

Contributors

longshine avatar ucan927 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mina.net's Issues

Client mode in SslFilter

Problem

IoConnector should be able to add a SslFilter to enable SSL.

Solution

Commit 016c1cc fixed this issue.

Backward compatibility

No backward compatibility problems are expected.

Contributor

@ddfczm

SessionClosed event may not be fired when a connection is closed by remote peer.

Problem

If a connection is closed by the remote peer, a session may be stopped without being removed and notifying SessionClosed event, in which case the application will never know that this session has been terminated.

This is caused by incorrectly handling Socket Errors in SocketAsyncEventArgs.Completed callbacks, where SocketError.OperationAborted & SocketError.Interrupted are falsely ignored.

Solution

Commit d97272f fixes this issue.

Backward compatibility

No backward compatibility problems are expected.

Workaround

If you cannot upgrade to latest code, you can apply below workarounds:

WriteToClosedSessionException

If messages are written to a session whose underlying socket is actually disconnected, you can expect a WriteToClosedSessionException in the ExceptionCaught event.

udp广播报错

我发现有个 Broadcast方法,
IoConnector connector = new AsyncDatagramConnector();
IoBuffer buffer = IoBuffer.Allocate(64);
buffer.Put(data);
buffer.Flip();
connector.Broadcast(buffer);
马上有个异常报错了,Exception:以一种访问权限不允许的方式做了一个访问套接字的尝试。
增加 Socket.EnableBroadcast = true; 就没有异常了
但是我自己写的socket广播,也没有去设置EnableBroadcast ,也没报错。
初略一看,还没发现具体原因是什么。。。。

Filter MessageReceived中throw Exception没有执行Handler的ExceptionCaught

init

_connector = new AsyncSocketConnector();

            _connector.FilterChain.AddLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Encoding.UTF8)));
            _connector.FilterChain.AddLast("logger", new Log4UnityFilter());
            _connector.FilterChain.AddLast("json", new JsonFilter());
            _connector.FilterChain.AddLast("error", new ErrorMessageFilter());
            _connector.FilterChain.AddLast("identity", new IdentityFilter(deviceType));
            
            _connector.Handler = new SyncSendReceiveHandler();

Filter

public class ErrorMessageFilter : IoFilterAdapter
    {
        public override void MessageReceived(INextFilter nextFilter, IoSession session, object message)
        {
            ResponseMessage response = message as ResponseMessage;
            if (response == null)
                nextFilter.ExceptionCaught(session, new Exception("Wrong Used"));
            
            if(response.Error != null)
            {
                Exception cause = new Exception("[code]:" + response.Error.Code + " [message]:" + response.Error.Message);
                throw cause; // HERE
                nextFilter.ExceptionCaught(session, cause);
            }
            
            nextFilter.MessageReceived(session, message);
        }
    }

并没有执行Handler
当throw Exception时,进入到DefaultIoFilterChain中的

private void CallNext(IEntry<IoFilter, INextFilter> entry, Action<IoFilter, INextFilter> act, Action<Exception> error = null)
    {
      try
      {
        IoFilter filter = entry.Filter;
        INextFilter nextFilter = entry.NextFilter;
        act(filter, nextFilter);
      }
      catch (Exception ex)
      {
        if (error == null)
          
          this.FireExceptionCaught(ex);
        else
          error(ex);
      }
    }

进入FireExceptionCaught(ex),但是之后过后,并没有进入Handler

Unremoved lost sessions causes memory leak and unavailable service

Problem

In some cases, sessions of unexpectedly lost connections are not correctly removed. This will lead to a high memory consumption and cause the servcie to be unavailable to new connections.

Solution

Commit 37073ce and 587ab95 fixed this issue.

Workaround

If you cannot upgrade to latest code, you can apply below workarounds:

ExceptionCaught event

Make sure to close the related session by calling Session.Close() if you get a SocketException.

Backward compatibility

No backward compatibility problems are expected.

Mina.net 双向通信问题

现象:客户端成功连接服务端建立了Session,利用此session客户端发起的请求能收到服务端的应答;但后续服务端利用此session发起请求到客户端,会导致session关闭。
问题:请教mina.net是否支持双向通信?支持的话,怎么利用已建立的session,由服务端主动向客户端发起请求。

接收数据异常

程序正在接收大量数据时,如果突然断开网络,AsyncSocketSession.NET20.cs中BeginSend中的Socket.BeginSend(array.Array, array.Offset, array.Count, SocketFlags.None, SendCallback, new SendingContext(Socket, buf)); 方法会抛出SocketException异常,导致程序崩溃

AsyncSocketAcceptor无法监听客户端的连接请求

服务端使用AsyncSocketAcceptor监听端口时,在IMessageDecoder.Decode方法中出现
"Mina.Core.Buffer.BufferUnderflowException: 引发类型为“Mina.Core.Buffer.BufferUnderflowException”的异常。 在 Mina.Core.Buffer.Buffer.NextGetIndex(Int32 nb) 在 Mina.Core.Buffer.AbstractIoBuffer.GetInt32() 。"的错误,该错误发生时有用catch{}try{}捕捉处理该异常。但是新的客户端请求连接的时候服务端无法监听到,客户端返回"System.Net.SocketException(0x80004005):由于目标计算机积极拒绝,无法连接。"的错误。
观察服务端端口状态为Listening,重启服务端后客户端即可正常连接服务端。
请问该如何解决这个问题?谢谢!

Stack overflow caused by an infinite loop if a non-IoBuffer message is passed into socket session

Problem

In SocketSession.BeginSend(), if a non-IoBuffer or non-IFileRegion message is detected, an InvalidOperationException will be thrown into the EndSend() method, in which the BeginSend() will be fired again, while keeping the same faulty message as current request. This would lead to an infinite loop.

Solution

End sending and discard the current writing request if the message cannot be sent.

Commit 9616e9b fixed this issue.

Backward compatibility

No backward compatibility problems are expected.

常稳测试时Socket异常

程序在不稳定的网络环境下长时间运行时,偶遇如下异常:

System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled未处理的异常同步模块.vshost.exeSystem.Net.Sockets.SocketException, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089系统检测到在一个调用中尝试使用指针参数时的无效指针地址。 在 System.Net.Sockets.Socket.get_RemoteEndPoint()
在 Mina.Transport.Socket.AsyncSocketSession..ctor(IoService service, IoProcessor1 processor, Socket socket, Boolean reuseBuffer) 位置 D:\coding\vs2015\Mina.NET\Mina.NET\Transport\Socket\AsyncSocketSession.NET20.cs:行号 21 在 Mina.Transport.Socket.AsyncSocketConnector.ConnectCallback(IAsyncResult ar) 位置 D:\coding\vs2015\Mina.NET\Mina.NET\Transport\Socket\AsyncSocketConnector.NET20.cs:行号 52 在 System.Net.LazyAsyncResult.Complete(IntPtr userToken) 在 System.Net.ContextAwareResult.CompleteCallback(Object state) 在 System.Threading.ExecutionContext.runTryCode(Object userData) 在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Net.ContextAwareResult.Complete(IntPtr userToken) 在 System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) 在 System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)</StackTrace><ExceptionString>System.Net.Sockets.SocketException: 系统检测到在一个调用中尝试使用指针参数时的无效指针地址。 在 System.Net.Sockets.Socket.get_RemoteEndPoint() 在 Mina.Transport.Socket.AsyncSocketSession..ctor(IoService service, IoProcessor1 processor, Socket socket, Boolean reuseBuffer) 位置 D:\coding\vs2015\Mina.NET\Mina.NET\Transport\Socket\AsyncSocketSession.NET20.cs:行号 21
在 Mina.Transport.Socket.AsyncSocketConnector.ConnectCallback(IAsyncResult ar) 位置 D:\coding\vs2015\Mina.NET\Mina.NET\Transport\Socket\AsyncSocketConnector.NET20.cs:行号 52
在 System.Net.LazyAsyncResult.Complete(IntPtr userToken)
在 System.Net.ContextAwareResult.CompleteCallback(Object state)
在 System.Threading.ExecutionContext.runTryCode(Object userData)
在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Net.ContextAwareResult.Complete(IntPtr userToken)
在 System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
在 System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)271E

CompressionFilter

Do you plan to implement the existing Apache CompresionFilter?

I tried to do, but buffers confuse me

Wrong IoEventType enum definitions

Problem

The enum type IoEventType is not defined with bit-masked flags, causing all modules that rely on it fail to work properly, including ExecutorFilter with specific event types, WriteRequestFilter, ProfilerTimerFilter, CommonEventFilter, and the Loopback transport.

Solution

Commit b02d967 fixed this issue.

Backward compatibility

No backward compatibility problems are expected.

Multiple ProtocolCodecFilters cannot be stacked

Problem

The encoder output would be mixed up if multiple ProtocolCodecFilters are put into one same filter chain, since they share the same encoder/decoder outputs because of the same attribute keys.

Solution

The constructor of AttributeKey calls GetHashCode(), which will always returns (17 * 37) since the _name filed has NOT been set yet.

Backward compatibility

No backward compatibility problems are expected.

Write order

I searched the documentation and could not find any notes on the order of write operations.

Is the order of an Asynchronous Write guaranteed? Or would an Await() be needed after each to guarantee order?

Potential inconsistency in the pool of SocketAsyncEventArgs will cause InvalidOperationException when try to start a session

Problem

The AsyncSocketAcceptor (for .NET 4.0) listens to the SessionDestroyed event of a session, and returns its buffers for reading and writing to the buffer pool for reuse when it has been destroyed. This is how the reusable SocketAsyncEventArgs works, and it works fine, most time.

Normally the SessionDestroyed event will be fired after the socket closes.
However, since the socket is working asynchronously, the close operation may have not completely been done until some time later. Hence, the buffers returned to the pool may still be in use, making it inconsistent.
If a newly accepted session accquires one of those buffers and tries to begin receiving operation on it, it will throw a InvalidOperationException saying "A socket operation was already in progress".

Although the receiving operation will be started again even an exception occurs, this may be severe in high-load environment.

Backward compatibility

No backward compatibility problems are expected.

Performance issue

Hello i've noticed an issue on my Mina.Net based server, after awhile my server starts receiving data in small chunks instead of the full capacity of the buffer. I've traced the issue down to SocketAsyncEventArgsBuffer, the .Clear() method which is called prior to any receive, has no real effect on Capacity (as it returns _socketAsyncEventArgs.Count) and it may lead to performance degradation.

thanks

geo

update to Mina 2.1.5

Hi.
it is better to update to Mina 2.1.5 and use .net 6 for more performance.
can anybody update it?

Udp Client Demo Exception

First day try Mina.NET , try Udp Client Demo.
But throw exception:
mina-udpclient

I found 62line in code = "read = socket.EndReceiveFrom(ar, ref remoteEP);"

    private void ReceiveCallback(IAsyncResult ar)
    {
        System.Net.Sockets.Socket socket = (System.Net.Sockets.Socket)ar.AsyncState;
        Int32 read = 0;
        try
        {
            EndPoint remoteEP = Socket.RemoteEndPoint; 
            read = socket.EndReceiveFrom(ar, ref remoteEP);
        }
        catch (ObjectDisposedException)
        {
            // do nothing
            return;
        }
        catch (Exception ex)
        {
            EndReceive(ex);
            return;
        }

ArgumentOutOfRangeException when reading ssl streams in SslFilter

Problem

In certain occasion, an uncaught ArgumentOutOfRangeException may be thrown in method SslHandler.ReadBuffer().

This is caused by an invalid count argument when calling SslStream.Read(byte[] buffer, int offset, int count). To avoid overflow, it should be buf.Remaining, not buf.Capacity.

Besides, the capacity of buf is incorrectly enlarged.

Related with #15.

Solution

Fixes the incorrect count and capacity while reading from a SslStream, and do not write empty buffer into a SslStream.
Commit 5d6fcbd fixed this issue.

Backward compatibility

No backward compatibility problems are expected.

Contributor

@ddfczm

wrong code in SocketSession.EndReceive(Exception)

Problem

Instead of begin receiving again, SocketSession.EndReceive(Exception) faltily calls BeginSend(). The receiving process will stop, and exceptions might occur if the session has already begun sending.

Solution

Fixed in fe857ce.

Workaround

Most of the time this issue will not cause much trouble, since the method EndReceive(Exception) is only called in rare cases. If it does, please upgrade to the latest code.

UDP广播的问题

Hi,你好,

我们在使用中发现,如果AsyncDatagramConnector的实例对象调用Connect连接了一个广播地址,之后就无法收取不是从这个地址发出的UDP广播数据。我们尝试了Framework自带的UDPClient,发现不做连接,直接广播,收发一切正常。但是MINA的设计架构似乎一定要先有连接拿到ISession才能做通讯,哪怕是UDP...,因为我们整个系统基于.Net Framework4.0开发,而且必须支持XP,所以我们没法选择DotNetty,貌似Netty是不做连接的。计划用MINA.NET来改写之前的通讯模块,但是现在卡壳这里了,TCP工作的很好,但我们设备检测必须要用UDP,而广播检测消息之后,就无法收到设备的回复了。。。不知能否给些建议来解决这个问题?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.