Skip to content

Commit e2fdf75

Browse files
committed
Don't allow pings to prevent timeout
Sending a new request shouldn't clear the waiting-for-reply timeout if we haven't got a reply yet, or else we may never time out at all if we keep sending pings (which we do).
1 parent 1165c33 commit e2fdf75

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/stream-management/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export default function streamManagement({
124124
middleware.use(async (context, next) => {
125125
const { stanza } = context;
126126
clearTimeout(timeoutTimeout);
127+
timeoutTimeout = null;
127128
if (["presence", "message", "iq"].includes(stanza.name)) {
128129
sm.inbound += 1;
129130
} else if (stanza.is("r", NS)) {
@@ -158,14 +159,13 @@ export default function streamManagement({
158159
}
159160

160161
function requestAck() {
161-
clearTimeout(timeoutTimeout);
162162
clearTimeout(requestAckTimeout);
163163

164164
if (!sm.enabled) return;
165165

166-
if (sm.timeout) {
166+
if (sm.timeout && !timeoutTimeout) {
167167
timeoutTimeout = setTimeout(
168-
() => entity.disconnect().catch(() => {}),
168+
() => { clearTimeout(requestAckTimeout); entity.disconnect().catch(() => {}); },
169169
sm.timeout,
170170
);
171171
}

test/stream-management.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ test(
9393

9494
xmpp = client({ credentials, service: domain });
9595
xmpp.streamManagement.timeout = 10;
96+
xmpp.streamManagement.requestAckInterval = 5;
9697
xmpp.streamManagement.debounceAckRequest = 1;
9798
debug(xmpp);
9899

0 commit comments

Comments
 (0)