Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ type call struct {
}

func (c *call) finalize() {
if atomic.CompareAndSwapUint32(&c.finalized, 0, 1) {
c.done <- c
if !atomic.CompareAndSwapUint32(&c.finalized, 0, 1) {
panic("wsrpc: double call finalization")
}
c.done <- c
}

func (c *call) Result() (interface{}, error) {
Expand Down Expand Up @@ -498,12 +499,14 @@ func (c *Client) Go(ctx context.Context, method string, result interface{}, done
err = c.err
}
if err != nil {
// This may be called concurrently with out() -> setErr(), so
// finalize the error under the client mutex to prevent double
// finalization.
c.callMu.Lock()
delete(c.calls, id)
c.callMu.Unlock()
// call was not sent, safe to set and finalize error
call.err = err
call.finalize()
c.callMu.Unlock()
}
return call
}
Expand Down