Open ozgun77 opened 3 years ago
"任意客户端关闭后服务端尝试发送数据时抛出异常应合理,业务代理有责任处理这样的一场,也可以在发送之前检查一下连接状态。"
I'm checking the session state before sending message, but until I send message session is closed I guess. Do you have any suggestions to overcome this?
By the way this is StackTraceString:
at System.IO.Pipelines.ThrowHelper.ThrowInvalidOperationException_NoWritingAllowed()\n at System.IO.Pipelines.Pipe.GetSpan(Int32 sizeHint)\n at SuperSocket.WebSocket.WebSocketEncoder.EncodeSingleFragment(IBufferWriter1 writer, Byte opCode, Int32 expectedHeadLength, ReadOnlySpan
1 text)\n at SuperSocket.WebSocket.WebSocketEncoder.Encode(IBufferWriter1 writer, WebSocketPackage pack)\n at SuperSocket.Channel.PipeChannel
1.WritePackageWithEncoder[TPackage](IBufferWriter1 writer, IPackageEncoder
1 packageEncoder, TPackage package)\n at SuperSocket.Channel.PipeChannel1.SendAsync[TPackage](IPackageEncoder
1 packageEncoder, TPackage package)\n at SuperSocket.WebSocket.Server.WebSocketPackageHandler.Handle(IAppSession session, WebSocketPackage package)\n at SuperSocket.Server.PackageHandlingSchedulerBase`1.HandlePackageInternal(IAppSession session, TPackageInfo package)
Does this exception definitely occurs because of trying to send message after client closes connection?
@ozgun77 which version do you use?
@kerryjiang SuperSocket.WebSocket.Server 2.0.0-beta.8. Sometimes these errors getting too much, 10-15k errors for a minute.
@ozgun77 Could you upgrade to the latest beta? And is there a way to reproduce this problem?
Category: SuperSocketService EventId: 0 Session[355474cf-2d0e-42d3-9ee4-a4bfdbe4e4c9]: session exception. Exception: SuperSocket.PackageHandlingException1[SuperSocket.ProtoBase.StringPackageInfo]: Session 355474cf-2d0e-42d3-9ee4-a4bfdbe4e4c9 got an error when handle a package. ---> System.InvalidOperationException: Writing is not allowed after writer was completed. at System.IO.Pipelines.ThrowHelper.ThrowInvalidOperationException_NoWritingAllowed() at SuperSocket.Channel.PipeChannel
1.SendAsync(ReadOnlyMemory1 buffer) at WSDService.IoTServer.SendCommandAsync(IAppSession session, RequestCommand request) at WSDService.IoTServer.<>c__DisplayClass16_0.<<CreateServer>b__3>d.MoveNext() --- End of stack trace from previous location --- at SuperSocket.DelegatePackageHandler
1.Handle(IAppSession session, TReceivePackageInfo package) at SuperSocket.Server.PackageHandlingSchedulerBase`1.HandlePackageInternal(IAppSession session, TPackageInfo package) --- End of inner exception stack trace ---
I think this code in PipeChannel might causing this exception:
await Out.Writer.CompleteAsync().ConfigureAwait(false);
I think pipe is being closed before send task completed.
I am getting a similar error:
Handle is already used by another Socket.
at System.Net.Sockets.SocketAsyncEngine.RegisterCore(IntPtr socketHandle, SocketAsyncContext context)
at System.Net.Sockets.SocketAsyncEngine.RegisterSocket(IntPtr socketHandle, SocketAsyncContext context)
at System.Net.Sockets.SocketAsyncContext.Register()
at System.Net.Sockets.SocketAsyncContext.OperationQueue1.StartAsyncOperation(SocketAsyncContext context, TOperation operation, Int32 observedSequenceNumber, CancellationToken cancellationToken) at System.Net.Sockets.SocketAsyncContext.ReceiveAsync(Memory
1 buffer, SocketFlags flags, Int32& bytesReceived, Action5 callback, CancellationToken cancellationToken) at System.Net.Sockets.SocketAsyncEventArgs.DoOperationReceive(SafeSocketHandle handle, CancellationToken cancellationToken) at System.Net.Sockets.Socket.ReceiveAsync(SocketAsyncEventArgs e, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ReceiveAsync(Socket socket, CancellationToken cancellationToken) at System.Net.Sockets.Socket.ReceiveAsync(Memory
1 buffer, SocketFlags socketFlags, Boolean fromNetworkStream, CancellationToken cancellationToken)
at System.Net.Sockets.SocketTaskExtensions.ReceiveAsync(Socket socket, Memory1 buffer, SocketFlags socketFlags, CancellationToken cancellationToken) at SuperSocket.Channel.TcpPipeChannel
1.ReceiveAsync(Socket socket, Memory1 memory, SocketFlags socketFlags, CancellationToken cancellationToken) in C:\git_opensource\Supersocket\src\SuperSocket.Channel\TcpPipeChannel.cs:line 39 at SuperSocket.Channel.TcpPipeChannel
1.FillPipeWithDataAsync(Memory1 memory, CancellationToken cancellationToken) in C:\git_opensource\Supersocket\src\SuperSocket.Channel\TcpPipeChannel.cs:line 34 at SuperSocket.Channel.PipeChannel
1.FillPipeAsync(PipeWriter writer) in C:\git_opensource\Supersocket\src\SuperSocket.Channel\PipeChannel.cs:
await Out.Writer.CompleteAsync().ConfigureAwait(false);
Is there something to change here for a high volume client enviorment?
Doing further testing, with the same server instance, one in a windows server and a second in Ubuntu 20.04, it seems in Windows it has less ocurrence of the error and is more stable.
Hello,
I'm getting lots of "Writing is not allowed after writer was completed." exception when sending message in production. What can cause this error?
Thank you.