code-examples
code-examples copied to clipboard
3-durable.go
i renamed durable.go and i got the error below sometimes. I ran it within docker container. what's the problem? panic: sync: negative WaitGroup counter
goroutine 30 [running]: sync.(*WaitGroup).Add(0xc420088730, 0xffffffffffffffff) /usr/lib/go-1.10/src/sync/waitgroup.go:73 +0x133 sync.(*WaitGroup).Done(0xc420088730) /usr/lib/go-1.10/src/sync/waitgroup.go:98 +0x34 main.startSubscriber.func1(0xc42010a780) /usr/local/src/programs/gonats/durable.go:35 +0x132 github.com/nats-io/go-nats-streaming.(*conn).processMsg(0xc4200d6380, 0xc42011e3c0) /root/go/src/github.com/nats-io/go-nats-streaming/stan.go:751 +0x262 github.com/nats-io/go-nats-streaming.(*conn).(github.com/nats-io/go-nats-streaming.processMsg)-fm(0xc42011e3c0) /root/go/src/github.com/nats-io/go-nats-streaming/sub.go:228 +0x34 github.com/nats-io/go-nats.(*Conn).waitForMsgs(0xc4200dc000, 0xc4200da480) /root/go/src/github.com/nats-io/go-nats/nats.go:1702 +0x232 created by github.com/nats-io/go-nats.(*Conn).subscribe /root/go/src/github.com/nats-io/go-nats/nats.go:2424 +0x471
That error means wg.Done() was called more times than wg.Add(1) which means the first subscription may not have been closed correctly prior to the new one starting.. meaning there is a race condition somewhere.