Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.

Commit e99b37e

Browse files
nico-knfeywind
andauthored
fix(WaitForProcessing): Shutdown option WaitForProcessing never entered on subscription close (#2118)
* fix(WaitForProcessing): change entry condition * fix unit test to overwrite isEmpty() as a method instead of a getter * add fired events to docstrings * remove obsolete eslint exclusion * fix: change default to match existing behaviour --------- Co-authored-by: feywind <[email protected]>
1 parent 348210c commit e99b37e

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/lease-manager.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export class LeaseManager extends EventEmitter {
106106
* Adds a message to the inventory, kicking off the deadline extender if it
107107
* isn't already running.
108108
*
109+
* @fires LeaseManager#full
110+
*
109111
* @param {Message} message The message.
110112
* @private
111113
*/
@@ -141,6 +143,10 @@ export class LeaseManager extends EventEmitter {
141143
}
142144
/**
143145
* Removes ALL messages from inventory, and returns the ones removed.
146+
*
147+
* @fires LeaseManager#free
148+
* @fires LeaseManager#empty
149+
*
144150
* @private
145151
*/
146152
clear(): Message[] {
@@ -197,6 +203,7 @@ export class LeaseManager extends EventEmitter {
197203
* messages are left over.
198204
*
199205
* @fires LeaseManager#free
206+
* @fires LeaseManager#empty
200207
*
201208
* @param {Message} message The message to remove.
202209
* @private

src/subscriber.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ export class Message implements tracing.MessageWithAttributes {
655655
* close() function.
656656
* @property {SubscriberCloseBehavior} [options.behavior] The behavior of the close operation.
657657
* - NackImmediately: Sends nacks for all messages held by the client library, and
658-
* wait for them to send.
658+
* wait for them to send. (default to match old behavior)
659659
* - WaitForProcessing: Continues normal ack/nack and leasing processes until close
660660
* to the timeout, then switches to NackImmediately behavior to close down.
661661
* Use {@link SubscriberCloseBehaviors} for enum values.
@@ -970,9 +970,10 @@ export class Subscriber extends EventEmitter {
970970

971971
const options = this._options.closeOptions;
972972

973-
// If no behavior is specified, default to Wait.
973+
// If no behavior is specified, default to Nack. This most closely matches
974+
// the old behavior.
974975
const behavior =
975-
options?.behavior ?? SubscriberCloseBehaviors.WaitForProcessing;
976+
options?.behavior ?? SubscriberCloseBehaviors.NackImmediately;
976977

977978
// The timeout can't realistically be longer than the longest time we're willing
978979
// to lease messages.
@@ -1000,7 +1001,7 @@ export class Subscriber extends EventEmitter {
10001001
const shutdownStart = Date.now();
10011002
if (
10021003
behavior === SubscriberCloseBehaviors.WaitForProcessing &&
1003-
!this._inventory.isEmpty
1004+
!this._inventory.isEmpty()
10041005
) {
10051006
const waitTimeout = timeout.subtract(FINAL_NACK_TIMEOUT);
10061007

test/subscriber.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class FakeLeaseManager extends EventEmitter {
106106
remove(message: s.Message): void {}
107107

108108
_isEmpty = true;
109-
get isEmpty() {
109+
isEmpty(): boolean {
110110
return this._isEmpty;
111111
}
112112
}

0 commit comments

Comments
 (0)