@cosyte/mllp 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/dist/index.cjs +51 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -5
- package/dist/index.d.ts +56 -5
- package/dist/index.mjs +51 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.11
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- 6808571: A client can now bound how long it waits to establish a connection. New option `ClientOptions.connectTimeoutMs` (also on `createStarterClient`): an integer number of milliseconds from 1 to 2147483647 that covers the TCP connect and, with TLS on, the handshake after it. Unset means no bound, the behaviour so far, in which a connect to an address that drops packets waits on the operating system and a TLS handshake against a peer that accepts the TCP connection and never answers waits indefinitely. On expiry the socket is destroyed and `connect()` rejects with an `MllpConnectionError` whose `phase` is `connect` and whose `connectionCause` is the new `connect-timeout`; nothing was written, so no message can have reached the peer. On an auto-reconnect attempt the expiry feeds the reconnect policy like any other connect failure: `RetryContext.lastError` carries `code: "ETIMEDOUT"` and it is classified transient, so the client backs off and tries again. `ConnectionErrorCause` gains the member `connect-timeout`, so a caller that switches over every member of that union needs a case for it. A `connectTimeoutMs` that is not an integer in range throws a `RangeError` when the client is created.
|
|
7
|
+
|
|
3
8
|
## 0.1.10
|
|
4
9
|
### Patch Changes
|
|
5
10
|
|
package/dist/index.cjs
CHANGED
|
@@ -3239,6 +3239,14 @@ var OUTBOUND_WARNING_CONTEXT = Object.freeze({
|
|
|
3239
3239
|
byteOffset: 0,
|
|
3240
3240
|
elapsedSinceSendMs: 0
|
|
3241
3241
|
});
|
|
3242
|
+
var MAX_CONNECT_TIMEOUT_MS = 2147483647;
|
|
3243
|
+
var CONNECT_TIMEOUT_MESSAGE = "connect timed out: the connection, including its TLS handshake when TLS is on, was not established within connectTimeoutMs";
|
|
3244
|
+
var ConnectTimeoutCause = class extends Error {
|
|
3245
|
+
code = "ETIMEDOUT";
|
|
3246
|
+
constructor() {
|
|
3247
|
+
super(CONNECT_TIMEOUT_MESSAGE);
|
|
3248
|
+
}
|
|
3249
|
+
};
|
|
3242
3250
|
function identityOptions(host, servername) {
|
|
3243
3251
|
const target = servername ?? host;
|
|
3244
3252
|
if (net.isIP(target) === 0) return { servername: target };
|
|
@@ -3369,6 +3377,12 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3369
3377
|
*/
|
|
3370
3378
|
constructor(opts) {
|
|
3371
3379
|
super();
|
|
3380
|
+
const connectTimeoutMs = opts.connectTimeoutMs;
|
|
3381
|
+
if (connectTimeoutMs !== void 0 && !(Number.isInteger(connectTimeoutMs) && connectTimeoutMs >= 1 && connectTimeoutMs <= MAX_CONNECT_TIMEOUT_MS)) {
|
|
3382
|
+
throw new RangeError(
|
|
3383
|
+
"ClientOptions.connectTimeoutMs must be an integer from 1 to 2147483647, or left unset for no bound"
|
|
3384
|
+
);
|
|
3385
|
+
}
|
|
3372
3386
|
this._opts = opts;
|
|
3373
3387
|
this._ackTimeoutMs = opts.ackTimeoutMs ?? 3e4;
|
|
3374
3388
|
this._applicationAckTimeoutMs = opts.applicationAckTimeoutMs;
|
|
@@ -3412,6 +3426,9 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3412
3426
|
* TLS failures carry a `connectionCause`: `'tls-verify'` for certificate
|
|
3413
3427
|
* verification failures, `'tls-handshake'` for TLS-protocol-shaped failures
|
|
3414
3428
|
* ({@link isTlsProtocolError}); pure TCP failures carry none.
|
|
3429
|
+
* - `MllpConnectionError({ phase: 'connect', connectionCause: 'connect-timeout' })` if
|
|
3430
|
+
* {@link ClientOptions.connectTimeoutMs} is set and the TCP connect, or the TLS handshake
|
|
3431
|
+
* after it, did not complete in time. The socket is destroyed; nothing was written.
|
|
3415
3432
|
* - `MllpTlsConfigurationError` if the configured cipher-suite list cannot be
|
|
3416
3433
|
* honoured (the runtime rejects it, or `atnaTransportSecurity` and `ciphers`
|
|
3417
3434
|
* both declare one). Raised **before** a socket is opened, so nothing is left
|
|
@@ -3470,6 +3487,7 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3470
3487
|
const conn = new Connection(connOpts);
|
|
3471
3488
|
this._attachConnection(conn);
|
|
3472
3489
|
const connectEventName = this._opts.tls !== void 0 ? "secureConnect" : "connect";
|
|
3490
|
+
this._armConnectTimeout(socket, connectEventName);
|
|
3473
3491
|
const cleanup = () => {
|
|
3474
3492
|
if (signal !== void 0) {
|
|
3475
3493
|
signal.removeEventListener("abort", abortHandler);
|
|
@@ -3544,6 +3562,29 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3544
3562
|
});
|
|
3545
3563
|
return { socket, transport: new TlsTransport(socket) };
|
|
3546
3564
|
}
|
|
3565
|
+
/**
|
|
3566
|
+
* Bound one connection attempt by {@link ClientOptions.connectTimeoutMs}, when it is set.
|
|
3567
|
+
*
|
|
3568
|
+
* Armed after the `Connection` has registered its own socket listeners (its set-once
|
|
3569
|
+
* `onClose`/`onError` would otherwise remove ours). The timer stops at the socket's connect
|
|
3570
|
+
* event (`'secureConnect'` for TLS, so the handshake is inside the bound) or at its `'close'`,
|
|
3571
|
+
* whichever comes first; a refused connect or an abort therefore leaves no timer behind. On
|
|
3572
|
+
* expiry the socket is destroyed with a {@link ConnectTimeoutCause}, which reaches the same
|
|
3573
|
+
* `'error'` listeners as any other connect failure: `connect()` rejects, and a reconnect
|
|
3574
|
+
* attempt hands it to the reconnect classifier.
|
|
3575
|
+
*/
|
|
3576
|
+
_armConnectTimeout(socket, connectEventName) {
|
|
3577
|
+
const timeoutMs = this._opts.connectTimeoutMs;
|
|
3578
|
+
if (timeoutMs === void 0) return;
|
|
3579
|
+
const timer = setTimeout(() => {
|
|
3580
|
+
socket.destroy(new ConnectTimeoutCause());
|
|
3581
|
+
}, timeoutMs);
|
|
3582
|
+
const stop = () => {
|
|
3583
|
+
clearTimeout(timer);
|
|
3584
|
+
};
|
|
3585
|
+
socket.once(connectEventName, stop);
|
|
3586
|
+
socket.once("close", stop);
|
|
3587
|
+
}
|
|
3547
3588
|
/**
|
|
3548
3589
|
* Wrap a connect-phase socket error as `MllpConnectionError`, classifying
|
|
3549
3590
|
* TLS failures into the additive `connectionCause`:
|
|
@@ -3558,6 +3599,13 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3558
3599
|
* same shape as plaintext connect failures.
|
|
3559
3600
|
*/
|
|
3560
3601
|
_wrapConnectError(err, phase) {
|
|
3602
|
+
if (err instanceof ConnectTimeoutCause) {
|
|
3603
|
+
return new MllpConnectionError(err.message, {
|
|
3604
|
+
cause: err,
|
|
3605
|
+
phase,
|
|
3606
|
+
connectionCause: "connect-timeout"
|
|
3607
|
+
});
|
|
3608
|
+
}
|
|
3561
3609
|
if (this._opts.tls === void 0) {
|
|
3562
3610
|
return new MllpConnectionError(err.message, { cause: err, phase });
|
|
3563
3611
|
}
|
|
@@ -4050,6 +4098,7 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
4050
4098
|
this._emitNegotiatedTlsParameters(socket);
|
|
4051
4099
|
};
|
|
4052
4100
|
const connectEventName = this._opts.tls !== void 0 ? "secureConnect" : "connect";
|
|
4101
|
+
this._armConnectTimeout(socket, connectEventName);
|
|
4053
4102
|
socket.once("error", (sErr) => {
|
|
4054
4103
|
if (this._lastError === null || this._lastError.message !== sErr.message) {
|
|
4055
4104
|
this._lastError = sErr;
|
|
@@ -4862,6 +4911,7 @@ async function createStarterClient(opts) {
|
|
|
4862
4911
|
...opts.retryStrategy !== void 0 ? { retryStrategy: opts.retryStrategy } : {},
|
|
4863
4912
|
...opts.keepaliveIntervalMs !== void 0 ? { keepaliveIntervalMs: opts.keepaliveIntervalMs } : {},
|
|
4864
4913
|
...opts.deadPeerTimeoutMs !== void 0 ? { deadPeerTimeoutMs: opts.deadPeerTimeoutMs } : {},
|
|
4914
|
+
...opts.connectTimeoutMs !== void 0 ? { connectTimeoutMs: opts.connectTimeoutMs } : {},
|
|
4865
4915
|
...opts.tls !== void 0 ? { tls: opts.tls } : {}
|
|
4866
4916
|
};
|
|
4867
4917
|
const client = createClient(clientOpts);
|
|
@@ -5182,7 +5232,7 @@ async function runDifferential(options = {}) {
|
|
|
5182
5232
|
}
|
|
5183
5233
|
|
|
5184
5234
|
// src/index.ts
|
|
5185
|
-
var VERSION = "0.1.
|
|
5235
|
+
var VERSION = "0.1.11";
|
|
5186
5236
|
|
|
5187
5237
|
exports.ATNA_CIPHER_LIST = ATNA_CIPHER_LIST;
|
|
5188
5238
|
exports.ATNA_CIPHER_SUITES = ATNA_CIPHER_SUITES;
|