streamly icon indicating copy to clipboard operation
streamly copied to clipboard

Synchronous channel cleanup

Open harendra-kumar opened this issue 6 months ago • 0 comments

We throw ThreadAbort exception to running thread when the channel is stopped. Asynchronous exceptions can cause inadvertent problems because of unclean shutdown of the thread. It may leave the system in inconsistent state unless proper exception handling is implemented by the programmer. To avoid such issues we can also use a synchronous shutdown of streams by setting a flag and letting the thread abort itself. This would stop the thread before the next item in the stream is handled but the current action would not be interrupted. This could lead to delays in aborting the streams but would be safer than async signalling. This could be a config option, perhaps the default and the programmer can choose the other way if needed.

We can also have an option of a hybrid approach where we try to stop the threads synchronously first then after a timeout throw async exceptions.

harendra-kumar avatar Jun 27 '25 16:06 harendra-kumar