go-perun
go-perun copied to clipboard
Deadlock when accessing channel state
Location
package channel
Problem
When accessing the state of a channel, one must be careful not to do this while another channel operation (e.g., an update) is happening concurrently, as the result will be a deadlock. (For example, when using the OnUpdate
handler, one must not access the channel state from within the handler as the channel mutex is still locked.) Such deadlock instances are easy to run into and can be very hard to debug.
Proposal
It would be nice if we can access the channel state at any time, except when the internals actually are about to modify the state. At the moment the mutex is held throughout the whole update operation, for example. Also we should consider to return a copy of the state, and not a pointer, to ensure that we cannot alter the internal state from an external location.