From bae23ac76efbac8f87c68a93d8e2f72f05db9fc4 Mon Sep 17 00:00:00 2001 From: Alberto Ricart Date: Thu, 26 May 2022 13:31:32 -0500 Subject: [PATCH] [FIX] change transport.send() to not return a promise (#312) --- nats-base-client/protocol.ts | 8 +++----- nats-base-client/request.ts | 2 ++ nats-base-client/transport.ts | 2 +- src/deno_transport.ts | 14 ++++++++++---- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/nats-base-client/protocol.ts b/nats-base-client/protocol.ts index 741a6f8b..df7b7717 100644 --- a/nats-base-client/protocol.ts +++ b/nats-base-client/protocol.ts @@ -468,7 +468,7 @@ export class ProtocolHandler implements Dispatcher { } processPing() { - this.transport.send(PONG_CMD).catch(() => {/*ignoring socket error*/}); + this.transport.send(PONG_CMD); } processPong() { @@ -693,9 +693,7 @@ export class ProtocolHandler implements Dispatcher { } }); if (cmds.length) { - this.transport.send(encode(cmds.join(""))).catch( - () => {/*ignoring socket error*/}, - ); + this.transport.send(encode(cmds.join(""))); } } @@ -750,7 +748,7 @@ export class ProtocolHandler implements Dispatcher { if (this.outbound.size()) { const d = this.outbound.drain(); - this.transport.send(d).catch(() => {/*ignoring socket error*/}); + this.transport.send(d); } } diff --git a/nats-base-client/request.ts b/nats-base-client/request.ts index d0d2ae58..a891706f 100644 --- a/nats-base-client/request.ts +++ b/nats-base-client/request.ts @@ -81,6 +81,7 @@ export class RequestMany extends BaseRequest implements Request { this.done.then(() => { this.callback(null, null); }); + // @ts-ignore: node is not a number this.timer = setTimeout(() => { this.cancel(); }, opts.maxWait); @@ -110,6 +111,7 @@ export class RequestMany extends BaseRequest implements Request { if (this.opts.strategy === RequestStrategy.JitterTimer) { clearTimeout(this.timer); + // @ts-ignore: node is not a number this.timer = setTimeout(() => { this.cancel(); }, 300); diff --git a/nats-base-client/transport.ts b/nats-base-client/transport.ts index 58b7f24b..4277838d 100644 --- a/nats-base-client/transport.ts +++ b/nats-base-client/transport.ts @@ -73,7 +73,7 @@ export interface Transport extends AsyncIterable { isEncrypted(): boolean; - send(frame: Uint8Array): Promise; + send(frame: Uint8Array): void; close(err?: Error): Promise; diff --git a/src/deno_transport.ts b/src/deno_transport.ts index 3bee0210..c344f5fe 100644 --- a/src/deno_transport.ts +++ b/src/deno_transport.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 The NATS Authors + * Copyright 2020-2022 The NATS Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -33,7 +33,7 @@ import { } from "../nats-base-client/internal_mod.ts"; import type { TlsOptions } from "../nats-base-client/types.ts"; -const VERSION = "1.7.0"; +const VERSION = "1.7.1"; const LANG = "nats.deno"; // if trying to simply write to the connection for some reason @@ -223,8 +223,13 @@ export class DenoTransport implements Transport { }); } - send(frame: Uint8Array): Promise { - return this.enqueue(frame); + send(frame: Uint8Array): void { + const p = this.enqueue(frame); + p.catch((_err) => { + // we ignore write errors because client will + // fail on a read or when the heartbeat timer + // detects a stale connection + }); } isEncrypted(): boolean { @@ -247,6 +252,7 @@ export class DenoTransport implements Transport { try { // this is a noop but gives us a place to hang // a close and ensure that we sent all before closing + // we wait for the operation to fail or succeed await this.enqueue(TE.encode("")); } catch (err) { if (this.options.debug) {