Browse Source

socketClient: fix and test for StopForError deadlock

Fixes https://github.com/tendermint/abci/issues/114.

Fix and test for StopForError deadlock due to accidental
Mutex misuse. The test should return instantenously if
StopForError works without erraneous contention, lest it regressed.
pull/1780/head
Emmanuel Odeke 7 years ago
parent
commit
46d94f8325
No known key found for this signature in database GPG Key ID: 1CA47A292F89DD40
2 changed files with 29 additions and 1 deletions
  1. +1
    -1
      client/socket_client.go
  2. +28
    -0
      client/socket_client_test.go

+ 1
- 1
client/socket_client.go View File

@ -97,11 +97,11 @@ func (cli *socketClient) OnStop() {
// Stop the client and set the error
func (cli *socketClient) StopForError(err error) {
cli.mtx.Lock()
if !cli.IsRunning() {
return
}
cli.mtx.Lock()
if cli.err == nil {
cli.err = err
}


+ 28
- 0
client/socket_client_test.go View File

@ -0,0 +1,28 @@
package abcicli_test
import (
"errors"
"testing"
"time"
"github.com/tendermint/abci/client"
)
func TestSocketClientStopForErrorDeadlock(t *testing.T) {
c := abcicli.NewSocketClient(":80", false)
err := errors.New("foo-tendermint")
// See Issue https://github.com/tendermint/abci/issues/114
doneChan := make(chan bool)
go func() {
defer close(doneChan)
c.StopForError(err)
c.StopForError(err)
}()
select {
case <-doneChan:
case <-time.After(time.Second * 4):
t.Fatalf("Test took too long, potential deadlock still exists")
}
}

Loading…
Cancel
Save