Skip to content

Commit

Permalink
race fixes, let go1.5 set GOMAXPROCS
Browse files Browse the repository at this point in the history
  • Loading branch information
derekcollison committed Sep 18, 2015
1 parent 7e25c2b commit 004cd9e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
@@ -1,6 +1,5 @@
language: go
sudo: false

go:
- 1.4
- 1.5
Expand All @@ -16,8 +15,8 @@ script:
- go fmt ./...
- go vet ./...
- go test -i -race ./...
- GOMAXPROCS=1 go test -v -race ./...
- GOMAXPROCS=1 go test -v -covermode=count -coverprofile=coverage.out
- go test -v -race ./...
- go test -v -covermode=count -coverprofile=coverage.out
- $HOME/gopath/bin/goveralls -coverprofile coverage.out -service travis-ci
env:
global:
Expand Down
8 changes: 7 additions & 1 deletion nats.go
Expand Up @@ -1081,15 +1081,18 @@ func (nc *Conn) flusher() {
defer nc.wg.Done()

// snapshot the bw and conn since they can change from underneath of us.
nc.mu.Lock()
bw := nc.bw
conn := nc.conn
fch := nc.fch
nc.mu.Unlock()

if conn == nil || bw == nil {
return
}

for {
if _, ok := <-nc.fch; !ok {
if _, ok := <-fch; !ok {
return
}
nc.mu.Lock()
Expand Down Expand Up @@ -1619,6 +1622,9 @@ func (nc *Conn) resetPendingFlush() {

// This will clear any pending flush calls and release pending calls.
func (nc *Conn) clearPendingFlushCalls() {
nc.mu.Lock()
defer nc.mu.Unlock()

// Clear any queued pongs, e.g. pending flush calls.
for _, ch := range nc.pongs {
if ch != nil {
Expand Down
7 changes: 6 additions & 1 deletion test/sub_test.go
Expand Up @@ -221,9 +221,14 @@ func TestAsyncErrHandler(t *testing.T) {

ch := make(chan bool)

aeCalled := false

nc.Opts.AsyncErrorCB = func(c *nats.Conn, s *nats.Subscription, e error) {
// Suppress additional calls
nc.Opts.AsyncErrorCB = nil
if aeCalled {
return
}
aeCalled = true

if s != sub {
t.Fatal("Did not receive proper subscription")
Expand Down

0 comments on commit 004cd9e

Please sign in to comment.