Discovered while working on the privval: #2923 (comment)
SecretConnection is not thread safe since it has mutable state - multiple concurrent Read or concurrent Write will cause race conditions with access to things like the encryption nonces and the read buffer.
Note in the p2p layer, this has not been an issue, since Reads and Writes are already serialized by the recvRoutine and sendRoutine, respectively.
However, to properly implement net.Conn, the documentation specifies that:
Multiple goroutines may invoke methods on a Conn simultaneously
Thus we should add mutexes around the mutable encryption state.
Discovered while working on the privval: #2923 (comment)
SecretConnection is not thread safe since it has mutable state - multiple concurrent Read or concurrent Write will cause race conditions with access to things like the encryption nonces and the read buffer.
Note in the p2p layer, this has not been an issue, since Reads and Writes are already serialized by the recvRoutine and sendRoutine, respectively.
However, to properly implement net.Conn, the documentation specifies that:
Thus we should add mutexes around the mutable encryption state.