WebSocket4Net
WebSocket4Net copied to clipboard
Websocket hangs on certain proxies
Websocket can hang if used with some proxies.
After calling WebSocket.Open
no events (OnWsClosed, OnWsOpened, OnWsError
) are raised and some internal thread starts to generate high CPU usage.
More info:
ProxyConnectorBase.AsyncEventArgsCompleted
receives an empty buffer - SocketAsyncEventArgs.Buffer
is filled with zeros, Offset
and BytesTransferred
are 0. It calls HttpConnectProxy.ProcessReceive
where e.Buffer.SearchMark
returns -1 and executes this code:
if (result < 0)
{
int total = e.Offset + e.BytesTransferred;
if(total >= m_ReceiveBufferSize)
{
OnException("receive buffer size has been exceeded");
return;
}
e.SetBuffer(total, m_ReceiveBufferSize - total);
StartReceive(context.Socket, e);
return;
}
total
becomes 0 too, then StartReceive
is called, that raises ProxyConnectorBase.AsyncEventArgsCompleted
with empty buffer again and this loop continues infinitely.
I suggest a fix:
if (e.BytesTransferred == 0)
{
OnException("receive buffer is empty");
return;
}
But I'm not sure could BytesTransferred be zero in other healthy TCP connections.
Proxies to debug the issue with (there are plenty of them in varios online free proxies lists): 111.13.136.46:80 139.162.182.113:80 202.43.147.226:1080
The situation "e.BytesTransferred == 0" means the connection was closed.
I'm experiencing the same CPU intensive processing threads left behind on non-working proxies even though the WebSocket is properly disposed. Was this issue addressed in the latest release?
Thanks, Daniel