From 31efd76797f6f3c97762f1005d550fb37f2e3334 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 26 Mar 2015 13:25:23 +0000 Subject: [PATCH] eliminate potential deadlock/dealy in connection.Shutdown Treat the no-error case the same as the error case... - use the standard sendAction to communicate with the actor, which ensures that we don't block when the actor has terminated - run in a goroutine to prevent delaying the caller when the actor's channel is backed up. --- router/connection.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/router/connection.go b/router/connection.go index f3a88c2a..895cf222 100644 --- a/router/connection.go +++ b/router/connection.go @@ -188,12 +188,13 @@ func (conn *LocalConnection) SendProtocolMsg(m ProtocolMsg) { // Async func (conn *LocalConnection) Shutdown(err error) { - if err == nil { - conn.actionChan <- nil - } else { - // Run on its own goroutine in case the channel is backed up - go func() { conn.sendAction(func() error { return err }) }() - } + // Run on its own goroutine in case the channel is backed up + go func() { + if err == nil { + conn.sendAction(nil) + } else { + conn.sendAction(func() error { return err }) } + }() } // Async