Skip to content

p2p/conn: SecretConnection isn't thread safe #3110

@ebuchman

Description

@ebuchman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C:p2pComponent: P2P pkgT:validatorType: Validator related

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions