Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,8 @@ export class Subscriber extends EventEmitter {
const latency = (Date.now() - startTime) / 1000;
this._latencies.add(latency);

this._inventory.remove(message);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we wouldn't want to remove it in the case of a legit modack, just in the case of nack. But yeah, this clearly seems like an oversight.

Copy link
Author

Choose a reason for hiding this comment

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

The problem with not removing the message from the inventory is that the inventory will remain full forever in case of many nacks. If my maxMessages is 5 and I had 5 nacks, the inventory will remain full and the subscription will never receive messages again.

This is strange and hidden behavior. Some people have lost a little of their sanity trying to understand what was going on and why their subscription never received messages again.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah. When the user calls ack or nack, they're clearing asking for some kind of non-leasing behaviour, so removing it from the inventory in that case makes sense. For the (internal) modack case, though, we don't want to remove it. A nack is just a modack with a time of 0, so probably just adding a check there before removing it would be fine.


// No exception means Success.
return AckResponses.Success;
}
Expand Down
26 changes: 24 additions & 2 deletions test/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,32 @@ describe('Subscriber', () => {
});

describe('nack', () => {
it('should remove the message from the inventory', async () => {
const inventory: FakeLeaseManager = stubs.get('inventory');
const stub = sandbox.stub(inventory, 'remove').withArgs(message);

await subscriber.nack(message);

assert.strictEqual(stub.callCount, 1);
});
});

describe('nackWithResponse', () => {
it('should remove the message from the inventory', async () => {
const inventory: FakeLeaseManager = stubs.get('inventory');
const stub = sandbox.stub(inventory, 'remove').withArgs(message);

await subscriber.nackWithResponse(message);

assert.strictEqual(stub.callCount, 1);
});
});

describe('ackWithResponse', () => {
it('should modAck the message with a 0 deadline', async () => {
const stub = sandbox.stub(subscriber, 'modAck');

await subscriber.nack(message);
await subscriber.ackWithResponse(message);

const [msg, deadline] = stub.lastCall.args;

Expand All @@ -946,7 +968,7 @@ describe('Subscriber', () => {
const inventory: FakeLeaseManager = stubs.get('inventory');
const stub = sandbox.stub(inventory, 'remove').withArgs(message);

await subscriber.nack(message);
await subscriber.ackWithResponse(message);

assert.strictEqual(stub.callCount, 1);
});
Expand Down
Loading