Skip to content
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

TcpClient.Close() throws ObjectDisposedException when disposing of the writer #7

Open
jupjohn opened this issue Sep 13, 2021 · 1 comment

Comments

@jupjohn
Copy link

jupjohn commented Sep 13, 2021

I've encountered a crash when calling ITwitchClient.Disconnect() where TcpClient.Close() (all implementations) will throw when disposing of the StreamWriter. This seems to be caused by the line before that disposes of the client's StreamReader which indirectly closes the SslStream shared with the StreamWriter.

@jupjohn
Copy link
Author

jupjohn commented Sep 13, 2021

Relevant stacktrace (bot is run inside a hosted service, hence the references):

Unhandled exception. System.AggregateException: One or more hosted services failed to stop. (Cannot access a disposed object.
Object name: 'SslStream'.)
 ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SslStream'.
   at System.Net.Security.SslStream.<ThrowIfExceptional>g__ThrowExceptional|137_0(ExceptionDispatchInfo e)
   at System.Net.Security.SslStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
   at System.IO.StreamWriter.Dispose(Boolean disposing)
   at System.IO.TextWriter.Dispose()
   at TwitchLib.Communication.Clients.TcpClient.Close(Boolean callDisconnect)
   at TwitchLib.Client.TwitchClient.Disconnect()
   (removed for brevity)

@Bukk94 Bukk94 mentioned this issue Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant