Skip to content

Commit

Permalink
cannot use refresh on cleared timer
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Mar 25, 2022
1 parent 1599a1c commit 74d3718
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/cmap/connection.ts
Expand Up @@ -258,13 +258,9 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
stream.on('close', () => this.handleIssue({ isClose: true }));

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

// hook the message stream up to the passed in stream
Expand Down Expand Up @@ -722,6 +718,7 @@ 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
5 changes: 2 additions & 3 deletions test/tools/utils.ts
Expand Up @@ -13,7 +13,6 @@ export function makeTestFunction(config: DeprecateOptionsConfig) {
}

export function ensureCalledWith(stub: any, args: any[]) {
// @ts-expect-error: sinonChai plugin
args.forEach((m: any) => expect(stub).to.have.been.calledWith(m));
}

Expand All @@ -33,7 +32,7 @@ ClassWithLogger.prototype.getLogger = function () {
};

// creation of class without a logger
function ClassWithoutLogger() {
export function ClassWithoutLogger() {
// empty function for class
}

Expand All @@ -44,7 +43,7 @@ ClassWithoutLogger.prototype.f = makeTestFunction({
});

// creation of class where getLogger returns undefined
function ClassWithUndefinedLogger() {
export function ClassWithUndefinedLogger() {
// empty function for class
}

Expand Down

0 comments on commit 74d3718

Please sign in to comment.