Skip to content

Commit

Permalink
Fix netchan encoder's call to async err callback.
Browse files Browse the repository at this point in the history
Check closed state and send into async cb channel under conn's lock.
  • Loading branch information
kozlovic committed Jan 28, 2016
1 parent 2d075b4 commit dce2211
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion netchan.go
Expand Up @@ -31,10 +31,14 @@ func chPublish(c *EncodedConn, chVal reflect.Value, subject string) {
return
}
if e := c.Publish(subject, val.Interface()); e != nil {
// Do this under lock.
c.Conn.mu.Lock()
defer c.Conn.mu.Unlock()

if c.Conn.Opts.AsyncErrorCB != nil {
// FIXME(dlc) - Not sure this is the right thing to do.
// FIXME(ivan) - If the connection is not yet closed, try to schedule the callback
if c.Conn.IsClosed() {
if c.Conn.isClosed() {
go c.Conn.Opts.AsyncErrorCB(c.Conn, nil, e)
} else {
c.Conn.ach <- func() { c.Conn.Opts.AsyncErrorCB(c.Conn, nil, e) }
Expand Down

0 comments on commit dce2211

Please sign in to comment.