Closed aler9 closed 1 year ago
Patch coverage: 75.00%
and project coverage change: -0.07%
:warning:
Comparison is base (
6f06385
) 62.98% compared to head (7018d5a
) 62.91%. Report is 4 commits behind head on main.
:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Hello, calling
Conn.Close()
currently results in multiple race conditions and in possible crashes due to the fact that some channels are closed before routines that make use of them are closed.Closing a channel while writing to it causes a race condition, because writing to a channel is a read+write operation, and closing a channel and then writing to it causes a crash.
In
Conn.Close()
shutdown is set to true andclose(c.writeQueue)
is called, but it's still possible for another routine to write toc.writeQueue
because this routine may have already passed theisShutdown()
check:The correct way to deal with this issue in an atomic way consists in using a context. In
Conn.Close()
, this context is canceled:In routines,
isShutdown()
is removed and theselect {}
statement is improved in order to abort the read operation if the context is canceled:The same can be done for all read and write operations on channels.
isShutdown()
,shutdown
andshutdownMutex
become useless and they can be removed.The same context can be used to terminate all routines concurrently, therefore existing contexts are removed and all routines are linked to the same context.