p2p: fix Peer shutdown deadlocks
There were multiple synchronization issues in the disconnect handling, all caused by the odd special-casing of Peer.readLoop errors. Remove the special handling of read errors and make readLoop part of the Peer WaitGroup. Thanks to @Gustav-Simonsson for pointing at arrows in a diagram and playing rubber-duck.
This commit is contained in:
@ -98,15 +98,13 @@ func (d DiscReason) String() string {
|
||||
return discReasonToString[d]
|
||||
}
|
||||
|
||||
type discRequestedError DiscReason
|
||||
|
||||
func (err discRequestedError) Error() string {
|
||||
return fmt.Sprintf("disconnect requested: %v", DiscReason(err))
|
||||
func (d DiscReason) Error() string {
|
||||
return d.String()
|
||||
}
|
||||
|
||||
func discReasonForError(err error) DiscReason {
|
||||
if reason, ok := err.(discRequestedError); ok {
|
||||
return DiscReason(reason)
|
||||
if reason, ok := err.(DiscReason); ok {
|
||||
return reason
|
||||
}
|
||||
peerError, ok := err.(*peerError)
|
||||
if !ok {
|
||||
|
Reference in New Issue
Block a user