Skip to content

Answer every caller when close() is called more than once - #2836

Draft
delthas wants to merge 1 commit into
improvement/BB-833/answer-rebalance-callbacksfrom
improvement/BB-833/coalesce-close-callers
Draft

Answer every caller when close() is called more than once#2836
delthas wants to merge 1 commit into
improvement/BB-833/answer-rebalance-callbacksfrom
improvement/BB-833/coalesce-close-callers

Conversation

@delthas

@delthas delthas commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

The services install their SIGTERM handlers with process.on rather than once, so a repeated signal calls close() again. The second call started its own drain wait, overwriting the single drain slot the first was waiting on.

sequenceDiagram
    participant A as first caller
    participant C as BackbeatConsumer
    participant B as second caller
    A->>C: close()
    Note right of C: drain starts, first caller<br/>waits on the single drain slot
    B->>C: close() — SIGTERM repeated
    Note right of C: second wait overwrites the slot
    C-->>B: answered when the drain completes
    Note over A: never answered — released only by<br/>its own timeout, minutes after the<br/>consumer had already left the group
Loading

Changes

Coalesce instead: the first call runs the shutdown, later ones attach to it, and every caller is answered once it completes.

Verification

One unit test: closing twice answers both callers exactly once. It was checked against the previous implementation to confirm it fails there.

End-to-end measurement of the whole stack is in #2819.

Issue: BB-833

The services install their SIGTERM handlers with process.on rather than
once, so a repeated signal calls close() again. The second call started
its own drain wait, overwriting the single drain slot the first was
waiting on, and the first caller was then only released by its own
timeout, minutes after the consumer had already left the group.

Coalesce instead: the first call runs the shutdown, later ones attach to
it, and every caller is answered once it completes.

Issue: BB-833
@delthas
delthas force-pushed the improvement/BB-833/coalesce-close-callers branch from 573f054 to 46d1b26 Compare September 1, 2026 09:15
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.68%. Comparing base (44ebdf4) to head (46d1b26).

Additional details and impacted files

Impacted file tree graph

Files with missing lines Coverage Δ
lib/BackbeatConsumer.js 95.20% <100.00%> (+0.91%) ⬆️

... and 3 files with indirect coverage changes

Components Coverage Δ
Bucket Notification 80.27% <ø> (ø)
Core Library 81.65% <100.00%> (-0.33%) ⬇️
Ingestion 70.09% <ø> (ø)
Lifecycle 80.46% <ø> (ø)
Oplog Populator 85.83% <ø> (ø)
Replication 62.04% <ø> (+0.03%) ⬆️
Bucket Scanner 85.76% <ø> (ø)
@@                                Coverage Diff                                @@
##           improvement/BB-833/answer-rebalance-callbacks    #2836      +/-   ##
=================================================================================
- Coverage                                          75.80%   75.68%   -0.13%     
=================================================================================
  Files                                                200      200              
  Lines                                              13983    13990       +7     
=================================================================================
- Hits                                               10600    10588      -12     
- Misses                                              3373     3392      +19     
  Partials                                              10       10              
Flag Coverage Δ
api:retry 9.06% <0.00%> (-0.01%) ⬇️
api:routes 8.82% <0.00%> (-0.01%) ⬇️
bucket-scanner 85.76% <ø> (ø)
ft_test:queuepopulator 10.18% <12.50%> (-0.27%) ⬇️
ingestion 12.21% <0.00%> (-0.01%) ⬇️
lib 9.20% <75.00%> (+0.07%) ⬆️
lifecycle 19.47% <75.00%> (+0.04%) ⬆️
notification 1.01% <0.00%> (-0.01%) ⬇️
oplogPopulator 0.13% <0.00%> (-0.01%) ⬇️
replication 19.00% <75.00%> (+0.02%) ⬆️
unit 55.53% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@delthas
delthas marked this pull request as ready for review September 1, 2026 09:35
@delthas
delthas requested review from a team, DarkIsDude, SylvainSenechal and francoisferrand and removed request for SylvainSenechal September 1, 2026 09:35
@delthas

delthas commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Requested @francoisferrand in place of Sylvain Senechal, who is currently on PTO.

@francoisferrand francoisferrand left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the issue really the callbacks, or really just that the second call to close() should immediately abort (i.e. not trigger further drain/...) ?

i.e. find with that approach, but I wonder if just switch to once() (or a guard in the event handler) would not be simpler and more appropriate?

@delthas
delthas marked this pull request as draft September 1, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants