Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debounce stream management ack requests #1062

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
6 changes: 5 additions & 1 deletion packages/stream-management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function streamManagement({
}) {
let timeoutTimeout = null;
let requestAckTimeout = null;
let requestAckDebounce = null;

const sm = new EventEmitter();
Object.assign(sm, {
Expand All @@ -61,6 +62,7 @@ export default function streamManagement({
max: null,
timeout: 60_000,
requestAckInterval: 30_000,
requestAckDebounce: 100,
});

async function sendAck() {
Expand All @@ -72,6 +74,7 @@ export default function streamManagement({
entity.on("disconnect", () => {
clearTimeout(timeoutTimeout);
clearTimeout(requestAckTimeout);
clearTimeout(requestAckDebounce);
sm.enabled = false;
});

Expand Down Expand Up @@ -199,7 +202,8 @@ export default function streamManagement({

sm.outbound_q.push({ stanza, stamp: datetime() });
// Debounce requests so we send only one after a big run of stanza together
queueMicrotask(requestAck);
clearTimeout(requestAckDebounce);
setTimeout(requestAck, sm.requestAckDebounce);

return next();
});
Expand Down
Loading