Skip to content

Commit

Permalink
don't recreate timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Mar 25, 2022
1 parent 9563b76 commit 1599a1c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,13 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
stream.on('close', () => this.handleIssue({ isClose: true }));

stream.on('timeout', () => {
this.delayedTimeoutErrorId = setTimeout(() => {
this.handleIssue({ isTimeout: true, destroy: true });
}, 1);
if (this.delayedTimeoutErrorId != null) {
this.delayedTimeoutErrorId.refresh();
} else {
this.delayedTimeoutErrorId = setTimeout(() => {
this.handleIssue({ isTimeout: true, destroy: true });
}, 1);
}
});

// hook the message stream up to the passed in stream
Expand Down Expand Up @@ -718,7 +722,6 @@ function messageHandler(conn: Connection) {
return function messageHandler(message: BinMsg | Response) {
if (conn.delayedTimeoutErrorId != null) {
clearTimeout(conn.delayedTimeoutErrorId);
conn.delayedTimeoutErrorId = null;
}

// always emit the message, in case we are streaming
Expand Down

0 comments on commit 1599a1c

Please sign in to comment.