Commit 38b4d42
committed
fix(pubsub): count a published message while its batch lock is held
The failure callback decrements messagesWaiter for the messages it cancels
out of a MessagesBatch, but publish() incremented after releasing
messagesBatchLock. A message visible in the batch and not yet counted would
therefore be decremented for without ever having been counted, taking
pendingCount below zero and letting waitComplete() return early.
Incrementing while the lock is still held makes "in a MessagesBatch" and
"counted" one state. Lock ordering is messagesBatchLock -> Waiter monitor
here and nowhere the reverse, and incrementPendingCount never blocks. The
paused-key path still returns before the increment, as before.1 parent 7881111 commit 38b4d42
2 files changed
Lines changed: 8 additions & 15 deletions
File tree
- java-pubsub/google-cloud-pubsub/src
- main/java/com/google/cloud/pubsub/v1
- test/java/com/google/cloud/pubsub/v1
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
325 | 329 | | |
326 | 330 | | |
327 | 331 | | |
| |||
340 | 344 | | |
341 | 345 | | |
342 | 346 | | |
343 | | - | |
344 | | - | |
345 | 347 | | |
346 | 348 | | |
347 | 349 | | |
| |||
546 | 548 | | |
547 | 549 | | |
548 | 550 | | |
549 | | - | |
550 | | - | |
551 | | - | |
| 551 | + | |
| 552 | + | |
552 | 553 | | |
553 | 554 | | |
554 | 555 | | |
| |||
Lines changed: 2 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | 646 | | |
654 | 647 | | |
655 | 648 | | |
| |||
665 | 658 | | |
666 | 659 | | |
667 | 660 | | |
668 | | - | |
669 | | - | |
670 | | - | |
| 661 | + | |
| 662 | + | |
671 | 663 | | |
672 | 664 | | |
673 | 665 | | |
| |||
0 commit comments