-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Desktop] WebSocketException after listening 90+ seconds with .Net Framework, and its ok with .net core 2.0 #27192
Comments
Do you have minimal repro we can try locally? (i.e. is the code above complete?) |
I'm experiencing the same issue. c# ClientWebSocket will time out 90-100 seconds even when keepalives and data is moving across the wire. I'll try to work up a sharable sample if possible, but I found one possible explanation: as indicated from the stackoverflow article setting the service point manager max idle value does appear to keep my ClientWebSocket connection alive: ServicePointManager.MaxServicePointIdleTime = int.MaxValue; Here is a sample stack from my ClientWebSocket when not using the above workaround: System.Net.WebSockets.WebSocketException: The remote party closed the WebSocket connection without completing the close handshake. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SslStream'.
at System.Net.Security.SslState.CheckThrow(Boolean authSuccessCheck, Boolean shutdownCheck)
at System.Net.Security.SslState.get_SecureStream()
at System.Net.TlsStream.EndRead(IAsyncResult asyncResult)
at System.Net.PooledStream.EndRead(IAsyncResult asyncResult)
at System.IO.Stream.<>c.<BeginEndReadAsync>b__43_1(Stream stream, IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.WebSockets.WebSocketConnectionStream.<ReadAsync>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Net.WebSockets.WebSocketBase.WebSocketOperation.<Process>d__19.MoveNext()
--- End of inner exception stack trace ---
at System.Net.WebSockets.WebSocketBase.WebSocketOperation.<Process>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.WebSockets.WebSocketBase.<ReceiveAsyncCore>d__45.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at [OMITTED].<NextAsync>d__8.MoveNext() in C:\[OMITTED].cs:line 125 |
@rdlaitila do you have a minimal repro that you could share with us? |
@karelz you can find a minimal repro solution here https://github.com/rdlaitila/corefx-issue-31880-repro Instructions
I've also included workarounds in the client and server projects that may be helpful in determining the issue. With the prior stackoverflow comments and some behavior notes, it would seem I am running the repro solution under Windows 10. Please let me know if you need any additional info from me. Thanks! |
@karelz here is the minimal repro, Thanks! using System;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace QD.BTC.Arbi.TestDemo
{
class TestGateio_ReproSslException
{
static void Main(string[] args)
{
Run();
Console.ReadLine();
}
private static async void Run()
{
var client = new ClientWebSocket()
{
Options = { KeepAliveInterval = new TimeSpan(0, 0, 5) }
};
var uri = new Uri("wss://ws.gate.io/v3/");
var _cancelation = new CancellationTokenSource();
await client.ConnectAsync(uri, _cancelation.Token);
var message = "{\"id\":52997,\"method\":\"depth.subscribe\",\"params\":[[\"ETH_USDT\",5,\"0\"]]}";
var buffer = Encoding.UTF8.GetBytes(message);
var messageSegment = new ArraySegment<byte>(buffer);
await client.SendAsync(messageSegment, WebSocketMessageType.Text, true, _cancelation.Token);
ArraySegment<Byte> bufferRecv = new ArraySegment<byte>(new Byte[8192]);
while (true)
{
try
{
var data = await client.ReceiveAsync(bufferRecv, _cancelation.Token);
Console.WriteLine(data.ToString());
}
catch (TaskCanceledException e)
{
Console.WriteLine(($"Listen ReceiveAsync TaskCanceledException : {e}."));
return;
}
catch (WebSocketException e)
{
Console.WriteLine(($"Listen ReceiveAsync WebSocketException : {e}."));
return;
}
catch (Exception e)
{
Console.WriteLine(($"Listen ReceiveAsync exception : {e}."));
return;
}
}
}
}
} |
Seems this is .NET Framework related issue. I'm only able to repro in .NET Framework, but I will let @kiddoneal @rdlaitila to confirm. Both repros provided are targeting .NET Framework, and in the issue description:
Initial analysis (on Framework code base):Like answered in StackOverflow question, this is caused by server sends back 101 response with
Thoughts:Server should never send Content-Length header in 1xx response (RFC 7230 Section 3.3.2). As a client, we can better handle this by adding logging for this scenario to help developer trouble-shooting the issue. Additional information:Response from
RFC 7230:
@dotnet/ncl @karelz |
Given that it is report against .NET Framework (which we do not track on GitHub - see repo main page) and given that primary problem is non-compliant server, we will close it here. |
Exception in ReceiveAsync in .NET Framework 4.7(4.7.1/4.7.2), Works in .NET core2.0 (2.1).
and its ok with the WebSocket4Net.dll in .NET Framework 4.7
reproduce:
here is the log:
my code looks like this :
The text was updated successfully, but these errors were encountered: