Skip to content
Open
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: 1 addition & 1 deletion handwritten/pubsub/src/lease-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ export class LeaseManager extends EventEmitter {
const deadline = this._subscriber.ackDeadline * 1000;
const latency = this._subscriber.modAckLatency;

return (deadline * 0.9 - latency) * jitter;
return Math.max(0, deadline * 0.9 - latency) * jitter;

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.

medium

While using Math.max(0, ...) prevents negative timeouts and the resulting Node.js warnings, returning 0 when latency exceeds 90% of the deadline can lead to immediate rescheduling of lease extensions. Under high latency or network congestion, this can cause a storm of rapid, back-to-back modAck requests, further exacerbating the latency issue.

Consider enforcing a reasonable minimum delay (e.g., 1000ms) to prevent spamming the server when latency is high.

Suggested change
return Math.max(0, deadline * 0.9 - latency) * jitter;
return Math.max(1000, deadline * 0.9 - latency) * jitter;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Currently it's negative, so 馃し

}
/**
* Schedules an deadline extension for all messages.
Expand Down
Loading