-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix negative WaitGroup counter issue #712
Fix negative WaitGroup counter issue #712
Conversation
Signed-off-by: xiaolongran <[email protected]>
var err error | ||
var msgID MessageID | ||
|
||
// use atomic bool to avoid race | ||
isDone := uAtomic.NewBool(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is isDone
needed? Each call to this function will get it's own channel instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as #711 desc, the callback of send is triggered multiple times, so the error as follows:
panic: sync: negative WaitGroup counter
goroutine 2204 [running]:
sync.(*WaitGroup).Add(0x18dbfc0, 0xc0020d8d40)
sync/waitgroup.go:74 +0x105
sync.(*WaitGroup).Done(...)
sync/waitgroup.go:99
github.com/apache/pulsar-client-go/pulsar.(*partitionProducer).Send.func1({0x1965558, 0xc01a1ab1d0}, 0xc01a841160, {0x0, 0x0})
github.com/apache/[email protected]/pulsar/producer_partition.go:722 +0x7e
github.com/apache/pulsar-client-go/pulsar.(*partitionProducer).ReceivedSendReceipt(0xc001017b00, 0xc017280480)
github.com/apache/[email protected]/pulsar/producer_partition.go:828 +0x7ef
github.com/apache/pulsar-client-go/pulsar/internal.(*connection).handleSendReceipt(0xc001188420, 0xc017280480)
github.com/apache/[email protected]/pulsar/internal/connection.go:673 +0xe8
github.com/apache/pulsar-client-go/pulsar/internal.(*connection).internalReceivedCommand(0xc001188420, 0xc006b31680, {0x0, 0x0})
github.com/apache/[email protected]/pulsar/internal/connection.go:558 +0x14a
github.com/apache/pulsar-client-go/pulsar/internal.(*connection).run(0xc001188420)
github.com/apache/[email protected]/pulsar/internal/connection.go:415 +0x3ba
github.com/apache/pulsar-client-go/pulsar/internal.(*connection).start.func1()
github.com/apache/[email protected]/pulsar/internal/connection.go:227 +0x65
created by github.com/apache/pulsar-client-go/pulsar/internal.(*connection).start
github.com/apache/[email protected]/pulsar/internal/connection.go:223 +0x75
So in the callback of send, we introduce the atomic variable of isDone
to ensure that at any time, for a send request, its callback will only be called once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this callback is still callback more than once, isDone is only check callback is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, use CAS to avoid this
Signed-off-by: xiaolongran <[email protected]>
time="2022-01-19T21:24:14+08:00" level=info msg="callback more than once for msgid , err: [ message send timeout: TimeoutError ], count 2" producerID=237 producer_name=xxxxx" |
Signed-off-by: xiaolongran <[email protected]>
Signed-off-by: xiaolongran [email protected]
Fixes #711
Motivation
As #711 desc, when the user calls
Send()
, we introduced waitgroup to ensure that the messageID is returned synchronously, but ininternalSendAsync()
, the callback may be triggered multiple times, causing the issue of #711Modifications
waitgroup
withdoneCh
, consistent with the implementation on the consumer side to facilitate subsequent code maintenanceclose(channel)
will only be triggered once