streadway / amqp

Go client for AMQP 0.9.1
http://godoc.org/github.com/streadway/amqp
BSD 2-Clause "Simplified" License
4.88k stars 621 forks source link

Deadlock in example_client when publish #448

Open CMonoceros opened 4 years ago

CMonoceros commented 4 years ago

Hi, I meet a deadlock when using the latest example.

Although increasing the size of notifyConfirm (https://github.com/streadway/amqp/pull/406), but the producer is blocked when resend more than once between one resend period. I test with one nanosecond resend delay and every time repeat it. Although in a production environment, it hard to realize it. But I think this example has a design defect.

Goroutine stack:

goroutine profile: total 9
2 @ 0x10323c0 0x10426b0 0x104269b 0x1042417 0x1078ecc 0x12494d6 0x1249011 0x12d7ca9 0x12d7927 0x12d9d2a 0x105f671
#   0x1042416   sync.runtime_SemacquireMutex+0x46                   /usr/local/Cellar/go/1.13.4/libexec/src/runtime/sema.go:71
#   0x1078ecb   sync.(*Mutex).lockSlow+0xfb                     /usr/local/Cellar/go/1.13.4/libexec/src/sync/mutex.go:138
#   0x12494d5   sync.(*Mutex).Lock+0x535                        /usr/local/Cellar/go/1.13.4/libexec/src/sync/mutex.go:81
#   0x1249010   github.com/streadway/amqp.(*Channel).Publish+0x70           /Users/zhangjunming/Code/GOPATH/pkg/mod/github.com/streadway/amqp@v0.0.0-20190827072141-edfb9018d271/channel.go:1331

1 @ 0x10323c0 0x1006b7b 0x1006b51 0x1006935 0x1249c77 0x1249ee0 0x12476b3 0x124793f 0x124bbb3 0x124b687 0x124be44 0x105f671
#   0x1249c76   github.com/streadway/amqp.(*confirms).confirm+0x96  /Users/zhangjunming/Code/GOPATH/pkg/mod/github.com/streadway/amqp@v0.0.0-20190827072141-edfb9018d271/confirms.go:45
#   0x1249edf   github.com/streadway/amqp.(*confirms).Multiple+0x7f /Users/zhangjunming/Code/GOPATH/pkg/mod/github.com/streadway/amqp@v0.0.0-20190827072141-edfb9018d271/confirms.go:79
#   0x12476b2   github.com/streadway/amqp.(*Channel).dispatch+0xa62 /Users/zhangjunming/Code/GOPATH/pkg/mod/github.com/streadway/amqp@v0.0.0-20190827072141-edfb9018d271/channel.go:312
#   0x124793e   github.com/streadway/amqp.(*Channel).recvMethod+0x23e   /Users/zhangjunming/Code/GOPATH/pkg/mod/github.com/streadway/amqp@v0.0.0-20190827072141-edfb9018d271/channel.go:351
#   0x124bbb2   github.com/streadway/amqp.(*Connection).dispatchN+0xd2  /Users/zhangjunming/Code/GOPATH/pkg/mod/github.com/streadway/amqp@v0.0.0-20190827072141-edfb9018d271/connection.go:477
#   0x124b686   github.com/streadway/amqp.(*Connection).demux+0x86  /Users/zhangjunming/Code/GOPATH/pkg/mod/github.com/streadway/amqp@v0.0.0-20190827072141-edfb9018d271/connection.go:436
#   0x124be43   github.com/streadway/amqp.(*Connection).reader+0xf3 /Users/zhangjunming/Code/GOPATH/pkg/mod/github.com/streadway/amqp@v0.0.0-20190827072141-edfb9018d271/connection.go:528

1 @ 0x10323c0 0x10426b0 0x104269b 0x1042417 0x1078ecc 0x1249bca 0x1249bd0 0x1249335 0x12d7ca9 0x12d7927 0x12d9d2a 0x105f671
#   0x1042416   sync.runtime_SemacquireMutex+0x46                   /usr/local/Cellar/go/1.13.4/libexec/src/runtime/sema.go:71
#   0x1078ecb   sync.(*Mutex).lockSlow+0xfb                     /usr/local/Cellar/go/1.13.4/libexec/src/sync/mutex.go:138
#   0x1249bc9   sync.(*Mutex).Lock+0xa9                         /usr/local/Cellar/go/1.13.4/libexec/src/sync/mutex.go:81
#   0x1249bcf   github.com/streadway/amqp.(*confirms).Publish+0xaf          /Users/zhangjunming/Code/GOPATH/pkg/mod/github.com/streadway/amqp@v0.0.0-20190827072141-edfb9018d271/confirms.go:32
#   0x1249334   github.com/streadway/amqp.(*Channel).Publish+0x394          /Users/zhangjunming/Code/GOPATH/pkg/mod/github.com/streadway/amqp@v0.0.0-20190827072141-edfb9018d271/channel.go:1360