.NET WebSockets forcibly closed despite keep-alive and activity on the connection

I ran into this issue this week. Your workaround got me pointed in the right direction, but I believe I’ve narrowed down the root cause.

If a “Content-Length: 0” header is included in the “101 Switching Protocols” response from a WebSocket server, WebSocketClient gets confused and schedules the connection for cleanup in 100 seconds.

Here’s the offending code from the .Net Reference Source:

//if the returned contentlength is zero, preemptively invoke calldone on the stream.
//this will wake up any pending reads.
if (m_ContentLength == 0 && m_ConnectStream is ConnectStream) {
    ((ConnectStream)m_ConnectStream).CallDone();
}

According to RFC 7230 Section 3.3.2, Content-Length is prohibited in 1xx (Informational) messages, but I’ve found it mistakenly included in some server implementations.

For additional details, including some sample code for diagnosing ServicePoint issues, see this thread: https://github.com/ably/ably-dotnet/issues/107

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)