An existing connection was forcibly closed by the remote host

my .NET plugin is often reading this Error message at System.Console.Out

An existing connection was forcibly closed by the remote host

It seems to come from McNeel.Network.Proxy.AuthenticatedProxyWebSocket.

It doesn’t bother me further though, I just thought I let you know.
Rhino and my plugin continue to work fine.

5/12/2021 12:13:07 PM|Fatal|<>c__DisplayClass9.<ReadBytesAsync>b__8|System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
                               at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
                               at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
                               --- End of inner exception stack trace ---
                               at System.Net.Security._SslStream.EndRead(IAsyncResult asyncResult)
                               at WebSocketSharp.Ext.<>c__DisplayClass9.<ReadBytesAsync>b__8(IAsyncResult ar)
5/12/2021 12:13:07 PM|Error|WebSocket.close|System.ObjectDisposedException: The CancellationTokenSource has been disposed.
                               at System.Threading.CancellationTokenSource.ThrowObjectDisposedException()
                               at System.Threading.CancellationTokenSource.InternalRegister(Action`1 callback, Object stateForCallback, SynchronizationContext targetSyncContext, ExecutionContext executionContext)
                               at System.Threading.CancellationToken.Register(Action`1 callback, Object state, Boolean useSynchronizationContext, Boolean useExecutionContext)
                               at System.Threading.CancellationToken.InternalRegisterWithoutEC(Action`1 callback, Object state)
                               at System.Threading.CancellationTokenSource.CreateLinkedTokenSource(CancellationToken token1, CancellationToken token2)
                               at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
                               at System.Net.Http.HttpClient.GetAsync(Uri requestUri, HttpCompletionOption completionOption, CancellationToken cancellationToken)
                               at McNeel.Network.Proxy.AuthenticatedProxyWebSocket.<>c__DisplayClass16_0.<Connect>b__1(Object sender, CloseEventArgs e)
                               at WebSocketSharp.Ext.Emit[TEventArgs](EventHandler`1 eventHandler, Object sender, TEventArgs e)
                               at WebSocketSharp.WebSocket.close(CloseEventArgs e, Boolean send, Boolean receive, Boolean received)

I see this often when broken into the process at a breakpoint for a prolonged time.

Anyway, assigned to @brian for further investigation.

Is your plugin at a breakpoint in the debugger when this happens? Is there anything else unique? Do you have any ideas about how to reproduce this (aside from Nathan’s suggestion of setting a breakpoint and waiting)?

@aj1, have you run into this when working with the AuthenticatedProxy?

I have not ran into this, but the problem appears to be that the CancellationToken is somehow getting referenced after it has gotten disposed.

My plugin is a F# scripting host. It has a Text view for console out stream to show anything that my script might print. Sometimes this error message appears there. But it doesn’t happen every day. Even if it’s open the whole day.

To reproduce it you could create a plugin that just redirects Console.Out to the rhino commandline window. Then wait till you see it there.