@solana/web3.js 1.95.3 → 1.95.4
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/lib/index.browser.cjs.js +82 -72
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +82 -72
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +751 -689
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +754 -692
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +10338 -10082
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +11 -11
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +82 -72
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -1
- package/src/connection.ts +6 -6
package/lib/index.esm.js
CHANGED
|
@@ -9,7 +9,7 @@ import { blob } from '@solana/buffer-layout';
|
|
|
9
9
|
import { toBigIntLE, toBufferLE } from 'bigint-buffer';
|
|
10
10
|
import require$$0 from 'util';
|
|
11
11
|
import require$$0$1 from 'http';
|
|
12
|
-
import require$$0$2, { Agent
|
|
12
|
+
import require$$0$2, { Agent } from 'https';
|
|
13
13
|
import { coerce, instance, string, tuple, literal, unknown, type, number, array, nullable, optional, boolean, record, union, create, any, assert as assert$1 } from 'superstruct';
|
|
14
14
|
import RpcClient from 'jayson/lib/client/browser';
|
|
15
15
|
import * as nodeFetch from 'node-fetch';
|
|
@@ -3378,163 +3378,171 @@ var agentkeepalive = {exports: {}};
|
|
|
3378
3378
|
* Helpers.
|
|
3379
3379
|
*/
|
|
3380
3380
|
|
|
3381
|
-
var
|
|
3382
|
-
var
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
*
|
|
3391
|
-
*
|
|
3392
|
-
*
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
* @api private
|
|
3422
|
-
*/
|
|
3423
|
-
|
|
3424
|
-
function parse(str) {
|
|
3425
|
-
str = String(str);
|
|
3426
|
-
if (str.length > 100) {
|
|
3427
|
-
return;
|
|
3428
|
-
}
|
|
3429
|
-
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
3430
|
-
str
|
|
3431
|
-
);
|
|
3432
|
-
if (!match) {
|
|
3433
|
-
return;
|
|
3434
|
-
}
|
|
3435
|
-
var n = parseFloat(match[1]);
|
|
3436
|
-
var type = (match[2] || 'ms').toLowerCase();
|
|
3437
|
-
switch (type) {
|
|
3438
|
-
case 'years':
|
|
3439
|
-
case 'year':
|
|
3440
|
-
case 'yrs':
|
|
3441
|
-
case 'yr':
|
|
3442
|
-
case 'y':
|
|
3443
|
-
return n * y;
|
|
3444
|
-
case 'weeks':
|
|
3445
|
-
case 'week':
|
|
3446
|
-
case 'w':
|
|
3447
|
-
return n * w;
|
|
3448
|
-
case 'days':
|
|
3449
|
-
case 'day':
|
|
3450
|
-
case 'd':
|
|
3451
|
-
return n * d;
|
|
3452
|
-
case 'hours':
|
|
3453
|
-
case 'hour':
|
|
3454
|
-
case 'hrs':
|
|
3455
|
-
case 'hr':
|
|
3456
|
-
case 'h':
|
|
3457
|
-
return n * h;
|
|
3458
|
-
case 'minutes':
|
|
3459
|
-
case 'minute':
|
|
3460
|
-
case 'mins':
|
|
3461
|
-
case 'min':
|
|
3462
|
-
case 'm':
|
|
3463
|
-
return n * m;
|
|
3464
|
-
case 'seconds':
|
|
3465
|
-
case 'second':
|
|
3466
|
-
case 'secs':
|
|
3467
|
-
case 'sec':
|
|
3468
|
-
case 's':
|
|
3469
|
-
return n * s;
|
|
3470
|
-
case 'milliseconds':
|
|
3471
|
-
case 'millisecond':
|
|
3472
|
-
case 'msecs':
|
|
3473
|
-
case 'msec':
|
|
3474
|
-
case 'ms':
|
|
3475
|
-
return n;
|
|
3476
|
-
default:
|
|
3477
|
-
return undefined;
|
|
3478
|
-
}
|
|
3479
|
-
}
|
|
3480
|
-
|
|
3481
|
-
/**
|
|
3482
|
-
* Short format for `ms`.
|
|
3483
|
-
*
|
|
3484
|
-
* @param {Number} ms
|
|
3485
|
-
* @return {String}
|
|
3486
|
-
* @api private
|
|
3487
|
-
*/
|
|
3381
|
+
var ms;
|
|
3382
|
+
var hasRequiredMs;
|
|
3383
|
+
|
|
3384
|
+
function requireMs () {
|
|
3385
|
+
if (hasRequiredMs) return ms;
|
|
3386
|
+
hasRequiredMs = 1;
|
|
3387
|
+
var s = 1000;
|
|
3388
|
+
var m = s * 60;
|
|
3389
|
+
var h = m * 60;
|
|
3390
|
+
var d = h * 24;
|
|
3391
|
+
var w = d * 7;
|
|
3392
|
+
var y = d * 365.25;
|
|
3393
|
+
|
|
3394
|
+
/**
|
|
3395
|
+
* Parse or format the given `val`.
|
|
3396
|
+
*
|
|
3397
|
+
* Options:
|
|
3398
|
+
*
|
|
3399
|
+
* - `long` verbose formatting [false]
|
|
3400
|
+
*
|
|
3401
|
+
* @param {String|Number} val
|
|
3402
|
+
* @param {Object} [options]
|
|
3403
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
3404
|
+
* @return {String|Number}
|
|
3405
|
+
* @api public
|
|
3406
|
+
*/
|
|
3407
|
+
|
|
3408
|
+
ms = function (val, options) {
|
|
3409
|
+
options = options || {};
|
|
3410
|
+
var type = typeof val;
|
|
3411
|
+
if (type === 'string' && val.length > 0) {
|
|
3412
|
+
return parse(val);
|
|
3413
|
+
} else if (type === 'number' && isFinite(val)) {
|
|
3414
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
3415
|
+
}
|
|
3416
|
+
throw new Error(
|
|
3417
|
+
'val is not a non-empty string or a valid number. val=' +
|
|
3418
|
+
JSON.stringify(val)
|
|
3419
|
+
);
|
|
3420
|
+
};
|
|
3488
3421
|
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3422
|
+
/**
|
|
3423
|
+
* Parse the given `str` and return milliseconds.
|
|
3424
|
+
*
|
|
3425
|
+
* @param {String} str
|
|
3426
|
+
* @return {Number}
|
|
3427
|
+
* @api private
|
|
3428
|
+
*/
|
|
3429
|
+
|
|
3430
|
+
function parse(str) {
|
|
3431
|
+
str = String(str);
|
|
3432
|
+
if (str.length > 100) {
|
|
3433
|
+
return;
|
|
3434
|
+
}
|
|
3435
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
3436
|
+
str
|
|
3437
|
+
);
|
|
3438
|
+
if (!match) {
|
|
3439
|
+
return;
|
|
3440
|
+
}
|
|
3441
|
+
var n = parseFloat(match[1]);
|
|
3442
|
+
var type = (match[2] || 'ms').toLowerCase();
|
|
3443
|
+
switch (type) {
|
|
3444
|
+
case 'years':
|
|
3445
|
+
case 'year':
|
|
3446
|
+
case 'yrs':
|
|
3447
|
+
case 'yr':
|
|
3448
|
+
case 'y':
|
|
3449
|
+
return n * y;
|
|
3450
|
+
case 'weeks':
|
|
3451
|
+
case 'week':
|
|
3452
|
+
case 'w':
|
|
3453
|
+
return n * w;
|
|
3454
|
+
case 'days':
|
|
3455
|
+
case 'day':
|
|
3456
|
+
case 'd':
|
|
3457
|
+
return n * d;
|
|
3458
|
+
case 'hours':
|
|
3459
|
+
case 'hour':
|
|
3460
|
+
case 'hrs':
|
|
3461
|
+
case 'hr':
|
|
3462
|
+
case 'h':
|
|
3463
|
+
return n * h;
|
|
3464
|
+
case 'minutes':
|
|
3465
|
+
case 'minute':
|
|
3466
|
+
case 'mins':
|
|
3467
|
+
case 'min':
|
|
3468
|
+
case 'm':
|
|
3469
|
+
return n * m;
|
|
3470
|
+
case 'seconds':
|
|
3471
|
+
case 'second':
|
|
3472
|
+
case 'secs':
|
|
3473
|
+
case 'sec':
|
|
3474
|
+
case 's':
|
|
3475
|
+
return n * s;
|
|
3476
|
+
case 'milliseconds':
|
|
3477
|
+
case 'millisecond':
|
|
3478
|
+
case 'msecs':
|
|
3479
|
+
case 'msec':
|
|
3480
|
+
case 'ms':
|
|
3481
|
+
return n;
|
|
3482
|
+
default:
|
|
3483
|
+
return undefined;
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3505
3486
|
|
|
3506
|
-
/**
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3487
|
+
/**
|
|
3488
|
+
* Short format for `ms`.
|
|
3489
|
+
*
|
|
3490
|
+
* @param {Number} ms
|
|
3491
|
+
* @return {String}
|
|
3492
|
+
* @api private
|
|
3493
|
+
*/
|
|
3494
|
+
|
|
3495
|
+
function fmtShort(ms) {
|
|
3496
|
+
var msAbs = Math.abs(ms);
|
|
3497
|
+
if (msAbs >= d) {
|
|
3498
|
+
return Math.round(ms / d) + 'd';
|
|
3499
|
+
}
|
|
3500
|
+
if (msAbs >= h) {
|
|
3501
|
+
return Math.round(ms / h) + 'h';
|
|
3502
|
+
}
|
|
3503
|
+
if (msAbs >= m) {
|
|
3504
|
+
return Math.round(ms / m) + 'm';
|
|
3505
|
+
}
|
|
3506
|
+
if (msAbs >= s) {
|
|
3507
|
+
return Math.round(ms / s) + 's';
|
|
3508
|
+
}
|
|
3509
|
+
return ms + 'ms';
|
|
3510
|
+
}
|
|
3513
3511
|
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
}
|
|
3512
|
+
/**
|
|
3513
|
+
* Long format for `ms`.
|
|
3514
|
+
*
|
|
3515
|
+
* @param {Number} ms
|
|
3516
|
+
* @return {String}
|
|
3517
|
+
* @api private
|
|
3518
|
+
*/
|
|
3519
|
+
|
|
3520
|
+
function fmtLong(ms) {
|
|
3521
|
+
var msAbs = Math.abs(ms);
|
|
3522
|
+
if (msAbs >= d) {
|
|
3523
|
+
return plural(ms, msAbs, d, 'day');
|
|
3524
|
+
}
|
|
3525
|
+
if (msAbs >= h) {
|
|
3526
|
+
return plural(ms, msAbs, h, 'hour');
|
|
3527
|
+
}
|
|
3528
|
+
if (msAbs >= m) {
|
|
3529
|
+
return plural(ms, msAbs, m, 'minute');
|
|
3530
|
+
}
|
|
3531
|
+
if (msAbs >= s) {
|
|
3532
|
+
return plural(ms, msAbs, s, 'second');
|
|
3533
|
+
}
|
|
3534
|
+
return ms + ' ms';
|
|
3535
|
+
}
|
|
3530
3536
|
|
|
3531
|
-
/**
|
|
3532
|
-
|
|
3533
|
-
|
|
3537
|
+
/**
|
|
3538
|
+
* Pluralization helper.
|
|
3539
|
+
*/
|
|
3534
3540
|
|
|
3535
|
-
function plural(ms, msAbs, n, name) {
|
|
3536
|
-
|
|
3537
|
-
|
|
3541
|
+
function plural(ms, msAbs, n, name) {
|
|
3542
|
+
var isPlural = msAbs >= n * 1.5;
|
|
3543
|
+
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
3544
|
+
}
|
|
3545
|
+
return ms;
|
|
3538
3546
|
}
|
|
3539
3547
|
|
|
3540
3548
|
/*!
|
|
@@ -3543,569 +3551,622 @@ function plural(ms, msAbs, n, name) {
|
|
|
3543
3551
|
* MIT Licensed
|
|
3544
3552
|
*/
|
|
3545
3553
|
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
*/
|
|
3554
|
+
var humanizeMs;
|
|
3555
|
+
var hasRequiredHumanizeMs;
|
|
3549
3556
|
|
|
3550
|
-
|
|
3551
|
-
|
|
3557
|
+
function requireHumanizeMs () {
|
|
3558
|
+
if (hasRequiredHumanizeMs) return humanizeMs;
|
|
3559
|
+
hasRequiredHumanizeMs = 1;
|
|
3552
3560
|
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
if (r === undefined) {
|
|
3557
|
-
var err = new Error(util.format('humanize-ms(%j) result undefined', t));
|
|
3558
|
-
console.warn(err.stack);
|
|
3559
|
-
}
|
|
3560
|
-
return r;
|
|
3561
|
-
};
|
|
3561
|
+
/**
|
|
3562
|
+
* Module dependencies.
|
|
3563
|
+
*/
|
|
3562
3564
|
|
|
3563
|
-
var
|
|
3564
|
-
|
|
3565
|
-
CURRENT_ID: Symbol('agentkeepalive#currentId'),
|
|
3566
|
-
CREATE_ID: Symbol('agentkeepalive#createId'),
|
|
3567
|
-
INIT_SOCKET: Symbol('agentkeepalive#initSocket'),
|
|
3568
|
-
CREATE_HTTPS_CONNECTION: Symbol('agentkeepalive#createHttpsConnection'),
|
|
3569
|
-
// socket
|
|
3570
|
-
SOCKET_CREATED_TIME: Symbol('agentkeepalive#socketCreatedTime'),
|
|
3571
|
-
SOCKET_NAME: Symbol('agentkeepalive#socketName'),
|
|
3572
|
-
SOCKET_REQUEST_COUNT: Symbol('agentkeepalive#socketRequestCount'),
|
|
3573
|
-
SOCKET_REQUEST_FINISHED_COUNT: Symbol('agentkeepalive#socketRequestFinishedCount'),
|
|
3574
|
-
};
|
|
3565
|
+
var util = require$$0;
|
|
3566
|
+
var ms = /*@__PURE__*/ requireMs();
|
|
3575
3567
|
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
SOCKET_REQUEST_FINISHED_COUNT,
|
|
3587
|
-
} = constants;
|
|
3588
|
-
|
|
3589
|
-
// OriginalAgent come from
|
|
3590
|
-
// - https://github.com/nodejs/node/blob/v8.12.0/lib/_http_agent.js
|
|
3591
|
-
// - https://github.com/nodejs/node/blob/v10.12.0/lib/_http_agent.js
|
|
3592
|
-
|
|
3593
|
-
// node <= 10
|
|
3594
|
-
let defaultTimeoutListenerCount = 1;
|
|
3595
|
-
const majorVersion = parseInt(process.version.split('.', 1)[0].substring(1));
|
|
3596
|
-
if (majorVersion >= 11 && majorVersion <= 12) {
|
|
3597
|
-
defaultTimeoutListenerCount = 2;
|
|
3598
|
-
} else if (majorVersion >= 13) {
|
|
3599
|
-
defaultTimeoutListenerCount = 3;
|
|
3568
|
+
humanizeMs = function (t) {
|
|
3569
|
+
if (typeof t === 'number') return t;
|
|
3570
|
+
var r = ms(t);
|
|
3571
|
+
if (r === undefined) {
|
|
3572
|
+
var err = new Error(util.format('humanize-ms(%j) result undefined', t));
|
|
3573
|
+
console.warn(err.stack);
|
|
3574
|
+
}
|
|
3575
|
+
return r;
|
|
3576
|
+
};
|
|
3577
|
+
return humanizeMs;
|
|
3600
3578
|
}
|
|
3601
3579
|
|
|
3602
|
-
|
|
3603
|
-
|
|
3580
|
+
var constants;
|
|
3581
|
+
var hasRequiredConstants;
|
|
3582
|
+
|
|
3583
|
+
function requireConstants () {
|
|
3584
|
+
if (hasRequiredConstants) return constants;
|
|
3585
|
+
hasRequiredConstants = 1;
|
|
3586
|
+
|
|
3587
|
+
constants = {
|
|
3588
|
+
// agent
|
|
3589
|
+
CURRENT_ID: Symbol('agentkeepalive#currentId'),
|
|
3590
|
+
CREATE_ID: Symbol('agentkeepalive#createId'),
|
|
3591
|
+
INIT_SOCKET: Symbol('agentkeepalive#initSocket'),
|
|
3592
|
+
CREATE_HTTPS_CONNECTION: Symbol('agentkeepalive#createHttpsConnection'),
|
|
3593
|
+
// socket
|
|
3594
|
+
SOCKET_CREATED_TIME: Symbol('agentkeepalive#socketCreatedTime'),
|
|
3595
|
+
SOCKET_NAME: Symbol('agentkeepalive#socketName'),
|
|
3596
|
+
SOCKET_REQUEST_COUNT: Symbol('agentkeepalive#socketRequestCount'),
|
|
3597
|
+
SOCKET_REQUEST_FINISHED_COUNT: Symbol('agentkeepalive#socketRequestFinishedCount'),
|
|
3598
|
+
};
|
|
3599
|
+
return constants;
|
|
3604
3600
|
}
|
|
3605
3601
|
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
options.socketActiveTTL = options.socketActiveTTL ? ms(options.socketActiveTTL) : 0;
|
|
3639
|
-
|
|
3640
|
-
super(options);
|
|
3641
|
-
|
|
3642
|
-
this[CURRENT_ID] = 0;
|
|
3643
|
-
|
|
3644
|
-
// create socket success counter
|
|
3645
|
-
this.createSocketCount = 0;
|
|
3646
|
-
this.createSocketCountLastCheck = 0;
|
|
3647
|
-
|
|
3648
|
-
this.createSocketErrorCount = 0;
|
|
3649
|
-
this.createSocketErrorCountLastCheck = 0;
|
|
3650
|
-
|
|
3651
|
-
this.closeSocketCount = 0;
|
|
3652
|
-
this.closeSocketCountLastCheck = 0;
|
|
3653
|
-
|
|
3654
|
-
// socket error event count
|
|
3655
|
-
this.errorSocketCount = 0;
|
|
3656
|
-
this.errorSocketCountLastCheck = 0;
|
|
3657
|
-
|
|
3658
|
-
// request finished counter
|
|
3659
|
-
this.requestCount = 0;
|
|
3660
|
-
this.requestCountLastCheck = 0;
|
|
3661
|
-
|
|
3662
|
-
// including free socket timeout counter
|
|
3663
|
-
this.timeoutSocketCount = 0;
|
|
3664
|
-
this.timeoutSocketCountLastCheck = 0;
|
|
3665
|
-
|
|
3666
|
-
this.on('free', socket => {
|
|
3667
|
-
// https://github.com/nodejs/node/pull/32000
|
|
3668
|
-
// Node.js native agent will check socket timeout eqs agent.options.timeout.
|
|
3669
|
-
// Use the ttl or freeSocketTimeout to overwrite.
|
|
3670
|
-
const timeout = this.calcSocketTimeout(socket);
|
|
3671
|
-
if (timeout > 0 && socket.timeout !== timeout) {
|
|
3672
|
-
socket.setTimeout(timeout);
|
|
3673
|
-
}
|
|
3674
|
-
});
|
|
3675
|
-
}
|
|
3676
|
-
|
|
3677
|
-
get freeSocketKeepAliveTimeout() {
|
|
3678
|
-
deprecate('agent.freeSocketKeepAliveTimeout is deprecated, please use agent.options.freeSocketTimeout instead');
|
|
3679
|
-
return this.options.freeSocketTimeout;
|
|
3680
|
-
}
|
|
3681
|
-
|
|
3682
|
-
get timeout() {
|
|
3683
|
-
deprecate('agent.timeout is deprecated, please use agent.options.timeout instead');
|
|
3684
|
-
return this.options.timeout;
|
|
3685
|
-
}
|
|
3686
|
-
|
|
3687
|
-
get socketActiveTTL() {
|
|
3688
|
-
deprecate('agent.socketActiveTTL is deprecated, please use agent.options.socketActiveTTL instead');
|
|
3689
|
-
return this.options.socketActiveTTL;
|
|
3690
|
-
}
|
|
3691
|
-
|
|
3692
|
-
calcSocketTimeout(socket) {
|
|
3693
|
-
/**
|
|
3694
|
-
* return <= 0: should free socket
|
|
3695
|
-
* return > 0: should update socket timeout
|
|
3696
|
-
* return undefined: not find custom timeout
|
|
3697
|
-
*/
|
|
3698
|
-
let freeSocketTimeout = this.options.freeSocketTimeout;
|
|
3699
|
-
const socketActiveTTL = this.options.socketActiveTTL;
|
|
3700
|
-
if (socketActiveTTL) {
|
|
3701
|
-
// check socketActiveTTL
|
|
3702
|
-
const aliveTime = Date.now() - socket[SOCKET_CREATED_TIME];
|
|
3703
|
-
const diff = socketActiveTTL - aliveTime;
|
|
3704
|
-
if (diff <= 0) {
|
|
3705
|
-
return diff;
|
|
3706
|
-
}
|
|
3707
|
-
if (freeSocketTimeout && diff < freeSocketTimeout) {
|
|
3708
|
-
freeSocketTimeout = diff;
|
|
3709
|
-
}
|
|
3710
|
-
}
|
|
3711
|
-
// set freeSocketTimeout
|
|
3712
|
-
if (freeSocketTimeout) {
|
|
3713
|
-
// set free keepalive timer
|
|
3714
|
-
// try to use socket custom freeSocketTimeout first, support headers['keep-alive']
|
|
3715
|
-
// https://github.com/node-modules/urllib/blob/b76053020923f4d99a1c93cf2e16e0c5ba10bacf/lib/urllib.js#L498
|
|
3716
|
-
const customFreeSocketTimeout = socket.freeSocketTimeout || socket.freeSocketKeepAliveTimeout;
|
|
3717
|
-
return customFreeSocketTimeout || freeSocketTimeout;
|
|
3718
|
-
}
|
|
3719
|
-
}
|
|
3720
|
-
|
|
3721
|
-
keepSocketAlive(socket) {
|
|
3722
|
-
const result = super.keepSocketAlive(socket);
|
|
3723
|
-
// should not keepAlive, do nothing
|
|
3724
|
-
if (!result) return result;
|
|
3725
|
-
|
|
3726
|
-
const customTimeout = this.calcSocketTimeout(socket);
|
|
3727
|
-
if (typeof customTimeout === 'undefined') {
|
|
3728
|
-
return true;
|
|
3729
|
-
}
|
|
3730
|
-
if (customTimeout <= 0) {
|
|
3731
|
-
debug('%s(requests: %s, finished: %s) free but need to destroy by TTL, request count %s, diff is %s',
|
|
3732
|
-
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT], customTimeout);
|
|
3733
|
-
return false;
|
|
3734
|
-
}
|
|
3735
|
-
if (socket.timeout !== customTimeout) {
|
|
3736
|
-
socket.setTimeout(customTimeout);
|
|
3737
|
-
}
|
|
3738
|
-
return true;
|
|
3739
|
-
}
|
|
3740
|
-
|
|
3741
|
-
// only call on addRequest
|
|
3742
|
-
reuseSocket(...args) {
|
|
3743
|
-
// reuseSocket(socket, req)
|
|
3744
|
-
super.reuseSocket(...args);
|
|
3745
|
-
const socket = args[0];
|
|
3746
|
-
const req = args[1];
|
|
3747
|
-
req.reusedSocket = true;
|
|
3748
|
-
const agentTimeout = this.options.timeout;
|
|
3749
|
-
if (getSocketTimeout(socket) !== agentTimeout) {
|
|
3750
|
-
// reset timeout before use
|
|
3751
|
-
socket.setTimeout(agentTimeout);
|
|
3752
|
-
debug('%s reset timeout to %sms', socket[SOCKET_NAME], agentTimeout);
|
|
3753
|
-
}
|
|
3754
|
-
socket[SOCKET_REQUEST_COUNT]++;
|
|
3755
|
-
debug('%s(requests: %s, finished: %s) reuse on addRequest, timeout %sms',
|
|
3756
|
-
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
|
|
3757
|
-
getSocketTimeout(socket));
|
|
3758
|
-
}
|
|
3759
|
-
|
|
3760
|
-
[CREATE_ID]() {
|
|
3761
|
-
const id = this[CURRENT_ID]++;
|
|
3762
|
-
if (this[CURRENT_ID] === Number.MAX_SAFE_INTEGER) this[CURRENT_ID] = 0;
|
|
3763
|
-
return id;
|
|
3764
|
-
}
|
|
3765
|
-
|
|
3766
|
-
[INIT_SOCKET$1](socket, options) {
|
|
3767
|
-
// bugfix here.
|
|
3768
|
-
// https on node 8, 10 won't set agent.options.timeout by default
|
|
3769
|
-
// TODO: need to fix on node itself
|
|
3770
|
-
if (options.timeout) {
|
|
3771
|
-
const timeout = getSocketTimeout(socket);
|
|
3772
|
-
if (!timeout) {
|
|
3773
|
-
socket.setTimeout(options.timeout);
|
|
3774
|
-
}
|
|
3775
|
-
}
|
|
3776
|
-
|
|
3777
|
-
if (this.options.keepAlive) {
|
|
3778
|
-
// Disable Nagle's algorithm: http://blog.caustik.com/2012/04/08/scaling-node-js-to-100k-concurrent-connections/
|
|
3779
|
-
// https://fengmk2.com/benchmark/nagle-algorithm-delayed-ack-mock.html
|
|
3780
|
-
socket.setNoDelay(true);
|
|
3781
|
-
}
|
|
3782
|
-
this.createSocketCount++;
|
|
3783
|
-
if (this.options.socketActiveTTL) {
|
|
3784
|
-
socket[SOCKET_CREATED_TIME] = Date.now();
|
|
3785
|
-
}
|
|
3786
|
-
// don't show the hole '-----BEGIN CERTIFICATE----' key string
|
|
3787
|
-
socket[SOCKET_NAME] = `sock[${this[CREATE_ID]()}#${options._agentKey}]`.split('-----BEGIN', 1)[0];
|
|
3788
|
-
socket[SOCKET_REQUEST_COUNT] = 1;
|
|
3789
|
-
socket[SOCKET_REQUEST_FINISHED_COUNT] = 0;
|
|
3790
|
-
installListeners(this, socket, options);
|
|
3791
|
-
}
|
|
3792
|
-
|
|
3793
|
-
createConnection(options, oncreate) {
|
|
3794
|
-
let called = false;
|
|
3795
|
-
const onNewCreate = (err, socket) => {
|
|
3796
|
-
if (called) return;
|
|
3797
|
-
called = true;
|
|
3602
|
+
var agent;
|
|
3603
|
+
var hasRequiredAgent;
|
|
3604
|
+
|
|
3605
|
+
function requireAgent () {
|
|
3606
|
+
if (hasRequiredAgent) return agent;
|
|
3607
|
+
hasRequiredAgent = 1;
|
|
3608
|
+
|
|
3609
|
+
const OriginalAgent = require$$0$1.Agent;
|
|
3610
|
+
const ms = /*@__PURE__*/ requireHumanizeMs();
|
|
3611
|
+
const debug = require$$0.debuglog('agentkeepalive');
|
|
3612
|
+
const {
|
|
3613
|
+
INIT_SOCKET,
|
|
3614
|
+
CURRENT_ID,
|
|
3615
|
+
CREATE_ID,
|
|
3616
|
+
SOCKET_CREATED_TIME,
|
|
3617
|
+
SOCKET_NAME,
|
|
3618
|
+
SOCKET_REQUEST_COUNT,
|
|
3619
|
+
SOCKET_REQUEST_FINISHED_COUNT,
|
|
3620
|
+
} = /*@__PURE__*/ requireConstants();
|
|
3621
|
+
|
|
3622
|
+
// OriginalAgent come from
|
|
3623
|
+
// - https://github.com/nodejs/node/blob/v8.12.0/lib/_http_agent.js
|
|
3624
|
+
// - https://github.com/nodejs/node/blob/v10.12.0/lib/_http_agent.js
|
|
3625
|
+
|
|
3626
|
+
// node <= 10
|
|
3627
|
+
let defaultTimeoutListenerCount = 1;
|
|
3628
|
+
const majorVersion = parseInt(process.version.split('.', 1)[0].substring(1));
|
|
3629
|
+
if (majorVersion >= 11 && majorVersion <= 12) {
|
|
3630
|
+
defaultTimeoutListenerCount = 2;
|
|
3631
|
+
} else if (majorVersion >= 13) {
|
|
3632
|
+
defaultTimeoutListenerCount = 3;
|
|
3633
|
+
}
|
|
3798
3634
|
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
}
|
|
3803
|
-
this[INIT_SOCKET$1](socket, options);
|
|
3804
|
-
oncreate(err, socket);
|
|
3805
|
-
};
|
|
3635
|
+
function deprecate(message) {
|
|
3636
|
+
console.log('[agentkeepalive:deprecated] %s', message);
|
|
3637
|
+
}
|
|
3806
3638
|
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3639
|
+
class Agent extends OriginalAgent {
|
|
3640
|
+
constructor(options) {
|
|
3641
|
+
options = options || {};
|
|
3642
|
+
options.keepAlive = options.keepAlive !== false;
|
|
3643
|
+
// default is keep-alive and 4s free socket timeout
|
|
3644
|
+
// see https://medium.com/ssense-tech/reduce-networking-errors-in-nodejs-23b4eb9f2d83
|
|
3645
|
+
if (options.freeSocketTimeout === undefined) {
|
|
3646
|
+
options.freeSocketTimeout = 4000;
|
|
3647
|
+
}
|
|
3648
|
+
// Legacy API: keepAliveTimeout should be rename to `freeSocketTimeout`
|
|
3649
|
+
if (options.keepAliveTimeout) {
|
|
3650
|
+
deprecate('options.keepAliveTimeout is deprecated, please use options.freeSocketTimeout instead');
|
|
3651
|
+
options.freeSocketTimeout = options.keepAliveTimeout;
|
|
3652
|
+
delete options.keepAliveTimeout;
|
|
3653
|
+
}
|
|
3654
|
+
// Legacy API: freeSocketKeepAliveTimeout should be rename to `freeSocketTimeout`
|
|
3655
|
+
if (options.freeSocketKeepAliveTimeout) {
|
|
3656
|
+
deprecate('options.freeSocketKeepAliveTimeout is deprecated, please use options.freeSocketTimeout instead');
|
|
3657
|
+
options.freeSocketTimeout = options.freeSocketKeepAliveTimeout;
|
|
3658
|
+
delete options.freeSocketKeepAliveTimeout;
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3661
|
+
// Sets the socket to timeout after timeout milliseconds of inactivity on the socket.
|
|
3662
|
+
// By default is double free socket timeout.
|
|
3663
|
+
if (options.timeout === undefined) {
|
|
3664
|
+
// make sure socket default inactivity timeout >= 8s
|
|
3665
|
+
options.timeout = Math.max(options.freeSocketTimeout * 2, 8000);
|
|
3666
|
+
}
|
|
3667
|
+
|
|
3668
|
+
// support humanize format
|
|
3669
|
+
options.timeout = ms(options.timeout);
|
|
3670
|
+
options.freeSocketTimeout = ms(options.freeSocketTimeout);
|
|
3671
|
+
options.socketActiveTTL = options.socketActiveTTL ? ms(options.socketActiveTTL) : 0;
|
|
3672
|
+
|
|
3673
|
+
super(options);
|
|
3674
|
+
|
|
3675
|
+
this[CURRENT_ID] = 0;
|
|
3676
|
+
|
|
3677
|
+
// create socket success counter
|
|
3678
|
+
this.createSocketCount = 0;
|
|
3679
|
+
this.createSocketCountLastCheck = 0;
|
|
3680
|
+
|
|
3681
|
+
this.createSocketErrorCount = 0;
|
|
3682
|
+
this.createSocketErrorCountLastCheck = 0;
|
|
3683
|
+
|
|
3684
|
+
this.closeSocketCount = 0;
|
|
3685
|
+
this.closeSocketCountLastCheck = 0;
|
|
3686
|
+
|
|
3687
|
+
// socket error event count
|
|
3688
|
+
this.errorSocketCount = 0;
|
|
3689
|
+
this.errorSocketCountLastCheck = 0;
|
|
3690
|
+
|
|
3691
|
+
// request finished counter
|
|
3692
|
+
this.requestCount = 0;
|
|
3693
|
+
this.requestCountLastCheck = 0;
|
|
3694
|
+
|
|
3695
|
+
// including free socket timeout counter
|
|
3696
|
+
this.timeoutSocketCount = 0;
|
|
3697
|
+
this.timeoutSocketCountLastCheck = 0;
|
|
3698
|
+
|
|
3699
|
+
this.on('free', socket => {
|
|
3700
|
+
// https://github.com/nodejs/node/pull/32000
|
|
3701
|
+
// Node.js native agent will check socket timeout eqs agent.options.timeout.
|
|
3702
|
+
// Use the ttl or freeSocketTimeout to overwrite.
|
|
3703
|
+
const timeout = this.calcSocketTimeout(socket);
|
|
3704
|
+
if (timeout > 0 && socket.timeout !== timeout) {
|
|
3705
|
+
socket.setTimeout(timeout);
|
|
3706
|
+
}
|
|
3707
|
+
});
|
|
3708
|
+
}
|
|
3709
|
+
|
|
3710
|
+
get freeSocketKeepAliveTimeout() {
|
|
3711
|
+
deprecate('agent.freeSocketKeepAliveTimeout is deprecated, please use agent.options.freeSocketTimeout instead');
|
|
3712
|
+
return this.options.freeSocketTimeout;
|
|
3713
|
+
}
|
|
3714
|
+
|
|
3715
|
+
get timeout() {
|
|
3716
|
+
deprecate('agent.timeout is deprecated, please use agent.options.timeout instead');
|
|
3717
|
+
return this.options.timeout;
|
|
3718
|
+
}
|
|
3719
|
+
|
|
3720
|
+
get socketActiveTTL() {
|
|
3721
|
+
deprecate('agent.socketActiveTTL is deprecated, please use agent.options.socketActiveTTL instead');
|
|
3722
|
+
return this.options.socketActiveTTL;
|
|
3723
|
+
}
|
|
3724
|
+
|
|
3725
|
+
calcSocketTimeout(socket) {
|
|
3726
|
+
/**
|
|
3727
|
+
* return <= 0: should free socket
|
|
3728
|
+
* return > 0: should update socket timeout
|
|
3729
|
+
* return undefined: not find custom timeout
|
|
3730
|
+
*/
|
|
3731
|
+
let freeSocketTimeout = this.options.freeSocketTimeout;
|
|
3732
|
+
const socketActiveTTL = this.options.socketActiveTTL;
|
|
3733
|
+
if (socketActiveTTL) {
|
|
3734
|
+
// check socketActiveTTL
|
|
3735
|
+
const aliveTime = Date.now() - socket[SOCKET_CREATED_TIME];
|
|
3736
|
+
const diff = socketActiveTTL - aliveTime;
|
|
3737
|
+
if (diff <= 0) {
|
|
3738
|
+
return diff;
|
|
3739
|
+
}
|
|
3740
|
+
if (freeSocketTimeout && diff < freeSocketTimeout) {
|
|
3741
|
+
freeSocketTimeout = diff;
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3744
|
+
// set freeSocketTimeout
|
|
3745
|
+
if (freeSocketTimeout) {
|
|
3746
|
+
// set free keepalive timer
|
|
3747
|
+
// try to use socket custom freeSocketTimeout first, support headers['keep-alive']
|
|
3748
|
+
// https://github.com/node-modules/urllib/blob/b76053020923f4d99a1c93cf2e16e0c5ba10bacf/lib/urllib.js#L498
|
|
3749
|
+
const customFreeSocketTimeout = socket.freeSocketTimeout || socket.freeSocketKeepAliveTimeout;
|
|
3750
|
+
return customFreeSocketTimeout || freeSocketTimeout;
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
|
|
3754
|
+
keepSocketAlive(socket) {
|
|
3755
|
+
const result = super.keepSocketAlive(socket);
|
|
3756
|
+
// should not keepAlive, do nothing
|
|
3757
|
+
if (!result) return result;
|
|
3758
|
+
|
|
3759
|
+
const customTimeout = this.calcSocketTimeout(socket);
|
|
3760
|
+
if (typeof customTimeout === 'undefined') {
|
|
3761
|
+
return true;
|
|
3762
|
+
}
|
|
3763
|
+
if (customTimeout <= 0) {
|
|
3764
|
+
debug('%s(requests: %s, finished: %s) free but need to destroy by TTL, request count %s, diff is %s',
|
|
3765
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT], customTimeout);
|
|
3766
|
+
return false;
|
|
3767
|
+
}
|
|
3768
|
+
if (socket.timeout !== customTimeout) {
|
|
3769
|
+
socket.setTimeout(customTimeout);
|
|
3770
|
+
}
|
|
3771
|
+
return true;
|
|
3772
|
+
}
|
|
3773
|
+
|
|
3774
|
+
// only call on addRequest
|
|
3775
|
+
reuseSocket(...args) {
|
|
3776
|
+
// reuseSocket(socket, req)
|
|
3777
|
+
super.reuseSocket(...args);
|
|
3778
|
+
const socket = args[0];
|
|
3779
|
+
const req = args[1];
|
|
3780
|
+
req.reusedSocket = true;
|
|
3781
|
+
const agentTimeout = this.options.timeout;
|
|
3782
|
+
if (getSocketTimeout(socket) !== agentTimeout) {
|
|
3783
|
+
// reset timeout before use
|
|
3784
|
+
socket.setTimeout(agentTimeout);
|
|
3785
|
+
debug('%s reset timeout to %sms', socket[SOCKET_NAME], agentTimeout);
|
|
3786
|
+
}
|
|
3787
|
+
socket[SOCKET_REQUEST_COUNT]++;
|
|
3788
|
+
debug('%s(requests: %s, finished: %s) reuse on addRequest, timeout %sms',
|
|
3789
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
|
|
3790
|
+
getSocketTimeout(socket));
|
|
3791
|
+
}
|
|
3792
|
+
|
|
3793
|
+
[CREATE_ID]() {
|
|
3794
|
+
const id = this[CURRENT_ID]++;
|
|
3795
|
+
if (this[CURRENT_ID] === Number.MAX_SAFE_INTEGER) this[CURRENT_ID] = 0;
|
|
3796
|
+
return id;
|
|
3797
|
+
}
|
|
3798
|
+
|
|
3799
|
+
[INIT_SOCKET](socket, options) {
|
|
3800
|
+
// bugfix here.
|
|
3801
|
+
// https on node 8, 10 won't set agent.options.timeout by default
|
|
3802
|
+
// TODO: need to fix on node itself
|
|
3803
|
+
if (options.timeout) {
|
|
3804
|
+
const timeout = getSocketTimeout(socket);
|
|
3805
|
+
if (!timeout) {
|
|
3806
|
+
socket.setTimeout(options.timeout);
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
|
|
3810
|
+
if (this.options.keepAlive) {
|
|
3811
|
+
// Disable Nagle's algorithm: http://blog.caustik.com/2012/04/08/scaling-node-js-to-100k-concurrent-connections/
|
|
3812
|
+
// https://fengmk2.com/benchmark/nagle-algorithm-delayed-ack-mock.html
|
|
3813
|
+
socket.setNoDelay(true);
|
|
3814
|
+
}
|
|
3815
|
+
this.createSocketCount++;
|
|
3816
|
+
if (this.options.socketActiveTTL) {
|
|
3817
|
+
socket[SOCKET_CREATED_TIME] = Date.now();
|
|
3818
|
+
}
|
|
3819
|
+
// don't show the hole '-----BEGIN CERTIFICATE----' key string
|
|
3820
|
+
socket[SOCKET_NAME] = `sock[${this[CREATE_ID]()}#${options._agentKey}]`.split('-----BEGIN', 1)[0];
|
|
3821
|
+
socket[SOCKET_REQUEST_COUNT] = 1;
|
|
3822
|
+
socket[SOCKET_REQUEST_FINISHED_COUNT] = 0;
|
|
3823
|
+
installListeners(this, socket, options);
|
|
3824
|
+
}
|
|
3825
|
+
|
|
3826
|
+
createConnection(options, oncreate) {
|
|
3827
|
+
let called = false;
|
|
3828
|
+
const onNewCreate = (err, socket) => {
|
|
3829
|
+
if (called) return;
|
|
3830
|
+
called = true;
|
|
3831
|
+
|
|
3832
|
+
if (err) {
|
|
3833
|
+
this.createSocketErrorCount++;
|
|
3834
|
+
return oncreate(err);
|
|
3835
|
+
}
|
|
3836
|
+
this[INIT_SOCKET](socket, options);
|
|
3837
|
+
oncreate(err, socket);
|
|
3838
|
+
};
|
|
3839
|
+
|
|
3840
|
+
const newSocket = super.createConnection(options, onNewCreate);
|
|
3841
|
+
if (newSocket) onNewCreate(null, newSocket);
|
|
3842
|
+
return newSocket;
|
|
3843
|
+
}
|
|
3844
|
+
|
|
3845
|
+
get statusChanged() {
|
|
3846
|
+
const changed = this.createSocketCount !== this.createSocketCountLastCheck ||
|
|
3847
|
+
this.createSocketErrorCount !== this.createSocketErrorCountLastCheck ||
|
|
3848
|
+
this.closeSocketCount !== this.closeSocketCountLastCheck ||
|
|
3849
|
+
this.errorSocketCount !== this.errorSocketCountLastCheck ||
|
|
3850
|
+
this.timeoutSocketCount !== this.timeoutSocketCountLastCheck ||
|
|
3851
|
+
this.requestCount !== this.requestCountLastCheck;
|
|
3852
|
+
if (changed) {
|
|
3853
|
+
this.createSocketCountLastCheck = this.createSocketCount;
|
|
3854
|
+
this.createSocketErrorCountLastCheck = this.createSocketErrorCount;
|
|
3855
|
+
this.closeSocketCountLastCheck = this.closeSocketCount;
|
|
3856
|
+
this.errorSocketCountLastCheck = this.errorSocketCount;
|
|
3857
|
+
this.timeoutSocketCountLastCheck = this.timeoutSocketCount;
|
|
3858
|
+
this.requestCountLastCheck = this.requestCount;
|
|
3859
|
+
}
|
|
3860
|
+
return changed;
|
|
3861
|
+
}
|
|
3862
|
+
|
|
3863
|
+
getCurrentStatus() {
|
|
3864
|
+
return {
|
|
3865
|
+
createSocketCount: this.createSocketCount,
|
|
3866
|
+
createSocketErrorCount: this.createSocketErrorCount,
|
|
3867
|
+
closeSocketCount: this.closeSocketCount,
|
|
3868
|
+
errorSocketCount: this.errorSocketCount,
|
|
3869
|
+
timeoutSocketCount: this.timeoutSocketCount,
|
|
3870
|
+
requestCount: this.requestCount,
|
|
3871
|
+
freeSockets: inspect(this.freeSockets),
|
|
3872
|
+
sockets: inspect(this.sockets),
|
|
3873
|
+
requests: inspect(this.requests),
|
|
3874
|
+
};
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3811
3877
|
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
this.timeoutSocketCount !== this.timeoutSocketCountLastCheck ||
|
|
3818
|
-
this.requestCount !== this.requestCountLastCheck;
|
|
3819
|
-
if (changed) {
|
|
3820
|
-
this.createSocketCountLastCheck = this.createSocketCount;
|
|
3821
|
-
this.createSocketErrorCountLastCheck = this.createSocketErrorCount;
|
|
3822
|
-
this.closeSocketCountLastCheck = this.closeSocketCount;
|
|
3823
|
-
this.errorSocketCountLastCheck = this.errorSocketCount;
|
|
3824
|
-
this.timeoutSocketCountLastCheck = this.timeoutSocketCount;
|
|
3825
|
-
this.requestCountLastCheck = this.requestCount;
|
|
3826
|
-
}
|
|
3827
|
-
return changed;
|
|
3828
|
-
}
|
|
3878
|
+
// node 8 don't has timeout attribute on socket
|
|
3879
|
+
// https://github.com/nodejs/node/pull/21204/files#diff-e6ef024c3775d787c38487a6309e491dR408
|
|
3880
|
+
function getSocketTimeout(socket) {
|
|
3881
|
+
return socket.timeout || socket._idleTimeout;
|
|
3882
|
+
}
|
|
3829
3883
|
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3884
|
+
function installListeners(agent, socket, options) {
|
|
3885
|
+
debug('%s create, timeout %sms', socket[SOCKET_NAME], getSocketTimeout(socket));
|
|
3886
|
+
|
|
3887
|
+
// listener socket events: close, timeout, error, free
|
|
3888
|
+
function onFree() {
|
|
3889
|
+
// create and socket.emit('free') logic
|
|
3890
|
+
// https://github.com/nodejs/node/blob/master/lib/_http_agent.js#L311
|
|
3891
|
+
// no req on the socket, it should be the new socket
|
|
3892
|
+
if (!socket._httpMessage && socket[SOCKET_REQUEST_COUNT] === 1) return;
|
|
3893
|
+
|
|
3894
|
+
socket[SOCKET_REQUEST_FINISHED_COUNT]++;
|
|
3895
|
+
agent.requestCount++;
|
|
3896
|
+
debug('%s(requests: %s, finished: %s) free',
|
|
3897
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT]);
|
|
3898
|
+
|
|
3899
|
+
// should reuse on pedding requests?
|
|
3900
|
+
const name = agent.getName(options);
|
|
3901
|
+
if (socket.writable && agent.requests[name] && agent.requests[name].length) {
|
|
3902
|
+
// will be reuse on agent free listener
|
|
3903
|
+
socket[SOCKET_REQUEST_COUNT]++;
|
|
3904
|
+
debug('%s(requests: %s, finished: %s) will be reuse on agent free event',
|
|
3905
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT]);
|
|
3906
|
+
}
|
|
3907
|
+
}
|
|
3908
|
+
socket.on('free', onFree);
|
|
3909
|
+
|
|
3910
|
+
function onClose(isError) {
|
|
3911
|
+
debug('%s(requests: %s, finished: %s) close, isError: %s',
|
|
3912
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT], isError);
|
|
3913
|
+
agent.closeSocketCount++;
|
|
3914
|
+
}
|
|
3915
|
+
socket.on('close', onClose);
|
|
3916
|
+
|
|
3917
|
+
// start socket timeout handler
|
|
3918
|
+
function onTimeout() {
|
|
3919
|
+
// onTimeout and emitRequestTimeout(_http_client.js)
|
|
3920
|
+
// https://github.com/nodejs/node/blob/v12.x/lib/_http_client.js#L711
|
|
3921
|
+
const listenerCount = socket.listeners('timeout').length;
|
|
3922
|
+
// node <= 10, default listenerCount is 1, onTimeout
|
|
3923
|
+
// 11 < node <= 12, default listenerCount is 2, onTimeout and emitRequestTimeout
|
|
3924
|
+
// node >= 13, default listenerCount is 3, onTimeout,
|
|
3925
|
+
// onTimeout(https://github.com/nodejs/node/pull/32000/files#diff-5f7fb0850412c6be189faeddea6c5359R333)
|
|
3926
|
+
// and emitRequestTimeout
|
|
3927
|
+
const timeout = getSocketTimeout(socket);
|
|
3928
|
+
const req = socket._httpMessage;
|
|
3929
|
+
const reqTimeoutListenerCount = req && req.listeners('timeout').length || 0;
|
|
3930
|
+
debug('%s(requests: %s, finished: %s) timeout after %sms, listeners %s, defaultTimeoutListenerCount %s, hasHttpRequest %s, HttpRequest timeoutListenerCount %s',
|
|
3931
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
|
|
3932
|
+
timeout, listenerCount, defaultTimeoutListenerCount, !!req, reqTimeoutListenerCount);
|
|
3933
|
+
if (debug.enabled) {
|
|
3934
|
+
debug('timeout listeners: %s', socket.listeners('timeout').map(f => f.name).join(', '));
|
|
3935
|
+
}
|
|
3936
|
+
agent.timeoutSocketCount++;
|
|
3937
|
+
const name = agent.getName(options);
|
|
3938
|
+
if (agent.freeSockets[name] && agent.freeSockets[name].indexOf(socket) !== -1) {
|
|
3939
|
+
// free socket timeout, destroy quietly
|
|
3940
|
+
socket.destroy();
|
|
3941
|
+
// Remove it from freeSockets list immediately to prevent new requests
|
|
3942
|
+
// from being sent through this socket.
|
|
3943
|
+
agent.removeSocket(socket, options);
|
|
3944
|
+
debug('%s is free, destroy quietly', socket[SOCKET_NAME]);
|
|
3945
|
+
} else {
|
|
3946
|
+
// if there is no any request socket timeout handler,
|
|
3947
|
+
// agent need to handle socket timeout itself.
|
|
3948
|
+
//
|
|
3949
|
+
// custom request socket timeout handle logic must follow these rules:
|
|
3950
|
+
// 1. Destroy socket first
|
|
3951
|
+
// 2. Must emit socket 'agentRemove' event tell agent remove socket
|
|
3952
|
+
// from freeSockets list immediately.
|
|
3953
|
+
// Otherise you may be get 'socket hang up' error when reuse
|
|
3954
|
+
// free socket and timeout happen in the same time.
|
|
3955
|
+
if (reqTimeoutListenerCount === 0) {
|
|
3956
|
+
const error = new Error('Socket timeout');
|
|
3957
|
+
error.code = 'ERR_SOCKET_TIMEOUT';
|
|
3958
|
+
error.timeout = timeout;
|
|
3959
|
+
// must manually call socket.end() or socket.destroy() to end the connection.
|
|
3960
|
+
// https://nodejs.org/dist/latest-v10.x/docs/api/net.html#net_socket_settimeout_timeout_callback
|
|
3961
|
+
socket.destroy(error);
|
|
3962
|
+
agent.removeSocket(socket, options);
|
|
3963
|
+
debug('%s destroy with timeout error', socket[SOCKET_NAME]);
|
|
3964
|
+
}
|
|
3965
|
+
}
|
|
3966
|
+
}
|
|
3967
|
+
socket.on('timeout', onTimeout);
|
|
3968
|
+
|
|
3969
|
+
function onError(err) {
|
|
3970
|
+
const listenerCount = socket.listeners('error').length;
|
|
3971
|
+
debug('%s(requests: %s, finished: %s) error: %s, listenerCount: %s',
|
|
3972
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
|
|
3973
|
+
err, listenerCount);
|
|
3974
|
+
agent.errorSocketCount++;
|
|
3975
|
+
if (listenerCount === 1) {
|
|
3976
|
+
// if socket don't contain error event handler, don't catch it, emit it again
|
|
3977
|
+
debug('%s emit uncaught error event', socket[SOCKET_NAME]);
|
|
3978
|
+
socket.removeListener('error', onError);
|
|
3979
|
+
socket.emit('error', err);
|
|
3980
|
+
}
|
|
3981
|
+
}
|
|
3982
|
+
socket.on('error', onError);
|
|
3983
|
+
|
|
3984
|
+
function onRemove() {
|
|
3985
|
+
debug('%s(requests: %s, finished: %s) agentRemove',
|
|
3986
|
+
socket[SOCKET_NAME],
|
|
3987
|
+
socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT]);
|
|
3988
|
+
// We need this function for cases like HTTP 'upgrade'
|
|
3989
|
+
// (defined by WebSockets) where we need to remove a socket from the
|
|
3990
|
+
// pool because it'll be locked up indefinitely
|
|
3991
|
+
socket.removeListener('close', onClose);
|
|
3992
|
+
socket.removeListener('error', onError);
|
|
3993
|
+
socket.removeListener('free', onFree);
|
|
3994
|
+
socket.removeListener('timeout', onTimeout);
|
|
3995
|
+
socket.removeListener('agentRemove', onRemove);
|
|
3996
|
+
}
|
|
3997
|
+
socket.on('agentRemove', onRemove);
|
|
3998
|
+
}
|
|
3844
3999
|
|
|
3845
|
-
|
|
3846
|
-
// https://github.com/nodejs/node/pull/21204/files#diff-e6ef024c3775d787c38487a6309e491dR408
|
|
3847
|
-
function getSocketTimeout(socket) {
|
|
3848
|
-
return socket.timeout || socket._idleTimeout;
|
|
3849
|
-
}
|
|
4000
|
+
agent = Agent;
|
|
3850
4001
|
|
|
3851
|
-
function
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
if (!socket._httpMessage && socket[SOCKET_REQUEST_COUNT] === 1) return;
|
|
3860
|
-
|
|
3861
|
-
socket[SOCKET_REQUEST_FINISHED_COUNT]++;
|
|
3862
|
-
agent.requestCount++;
|
|
3863
|
-
debug('%s(requests: %s, finished: %s) free',
|
|
3864
|
-
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT]);
|
|
3865
|
-
|
|
3866
|
-
// should reuse on pedding requests?
|
|
3867
|
-
const name = agent.getName(options);
|
|
3868
|
-
if (socket.writable && agent.requests[name] && agent.requests[name].length) {
|
|
3869
|
-
// will be reuse on agent free listener
|
|
3870
|
-
socket[SOCKET_REQUEST_COUNT]++;
|
|
3871
|
-
debug('%s(requests: %s, finished: %s) will be reuse on agent free event',
|
|
3872
|
-
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT]);
|
|
3873
|
-
}
|
|
3874
|
-
}
|
|
3875
|
-
socket.on('free', onFree);
|
|
3876
|
-
|
|
3877
|
-
function onClose(isError) {
|
|
3878
|
-
debug('%s(requests: %s, finished: %s) close, isError: %s',
|
|
3879
|
-
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT], isError);
|
|
3880
|
-
agent.closeSocketCount++;
|
|
3881
|
-
}
|
|
3882
|
-
socket.on('close', onClose);
|
|
3883
|
-
|
|
3884
|
-
// start socket timeout handler
|
|
3885
|
-
function onTimeout() {
|
|
3886
|
-
// onTimeout and emitRequestTimeout(_http_client.js)
|
|
3887
|
-
// https://github.com/nodejs/node/blob/v12.x/lib/_http_client.js#L711
|
|
3888
|
-
const listenerCount = socket.listeners('timeout').length;
|
|
3889
|
-
// node <= 10, default listenerCount is 1, onTimeout
|
|
3890
|
-
// 11 < node <= 12, default listenerCount is 2, onTimeout and emitRequestTimeout
|
|
3891
|
-
// node >= 13, default listenerCount is 3, onTimeout,
|
|
3892
|
-
// onTimeout(https://github.com/nodejs/node/pull/32000/files#diff-5f7fb0850412c6be189faeddea6c5359R333)
|
|
3893
|
-
// and emitRequestTimeout
|
|
3894
|
-
const timeout = getSocketTimeout(socket);
|
|
3895
|
-
const req = socket._httpMessage;
|
|
3896
|
-
const reqTimeoutListenerCount = req && req.listeners('timeout').length || 0;
|
|
3897
|
-
debug('%s(requests: %s, finished: %s) timeout after %sms, listeners %s, defaultTimeoutListenerCount %s, hasHttpRequest %s, HttpRequest timeoutListenerCount %s',
|
|
3898
|
-
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
|
|
3899
|
-
timeout, listenerCount, defaultTimeoutListenerCount, !!req, reqTimeoutListenerCount);
|
|
3900
|
-
if (debug.enabled) {
|
|
3901
|
-
debug('timeout listeners: %s', socket.listeners('timeout').map(f => f.name).join(', '));
|
|
3902
|
-
}
|
|
3903
|
-
agent.timeoutSocketCount++;
|
|
3904
|
-
const name = agent.getName(options);
|
|
3905
|
-
if (agent.freeSockets[name] && agent.freeSockets[name].indexOf(socket) !== -1) {
|
|
3906
|
-
// free socket timeout, destroy quietly
|
|
3907
|
-
socket.destroy();
|
|
3908
|
-
// Remove it from freeSockets list immediately to prevent new requests
|
|
3909
|
-
// from being sent through this socket.
|
|
3910
|
-
agent.removeSocket(socket, options);
|
|
3911
|
-
debug('%s is free, destroy quietly', socket[SOCKET_NAME]);
|
|
3912
|
-
} else {
|
|
3913
|
-
// if there is no any request socket timeout handler,
|
|
3914
|
-
// agent need to handle socket timeout itself.
|
|
3915
|
-
//
|
|
3916
|
-
// custom request socket timeout handle logic must follow these rules:
|
|
3917
|
-
// 1. Destroy socket first
|
|
3918
|
-
// 2. Must emit socket 'agentRemove' event tell agent remove socket
|
|
3919
|
-
// from freeSockets list immediately.
|
|
3920
|
-
// Otherise you may be get 'socket hang up' error when reuse
|
|
3921
|
-
// free socket and timeout happen in the same time.
|
|
3922
|
-
if (reqTimeoutListenerCount === 0) {
|
|
3923
|
-
const error = new Error('Socket timeout');
|
|
3924
|
-
error.code = 'ERR_SOCKET_TIMEOUT';
|
|
3925
|
-
error.timeout = timeout;
|
|
3926
|
-
// must manually call socket.end() or socket.destroy() to end the connection.
|
|
3927
|
-
// https://nodejs.org/dist/latest-v10.x/docs/api/net.html#net_socket_settimeout_timeout_callback
|
|
3928
|
-
socket.destroy(error);
|
|
3929
|
-
agent.removeSocket(socket, options);
|
|
3930
|
-
debug('%s destroy with timeout error', socket[SOCKET_NAME]);
|
|
3931
|
-
}
|
|
3932
|
-
}
|
|
3933
|
-
}
|
|
3934
|
-
socket.on('timeout', onTimeout);
|
|
3935
|
-
|
|
3936
|
-
function onError(err) {
|
|
3937
|
-
const listenerCount = socket.listeners('error').length;
|
|
3938
|
-
debug('%s(requests: %s, finished: %s) error: %s, listenerCount: %s',
|
|
3939
|
-
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
|
|
3940
|
-
err, listenerCount);
|
|
3941
|
-
agent.errorSocketCount++;
|
|
3942
|
-
if (listenerCount === 1) {
|
|
3943
|
-
// if socket don't contain error event handler, don't catch it, emit it again
|
|
3944
|
-
debug('%s emit uncaught error event', socket[SOCKET_NAME]);
|
|
3945
|
-
socket.removeListener('error', onError);
|
|
3946
|
-
socket.emit('error', err);
|
|
3947
|
-
}
|
|
3948
|
-
}
|
|
3949
|
-
socket.on('error', onError);
|
|
3950
|
-
|
|
3951
|
-
function onRemove() {
|
|
3952
|
-
debug('%s(requests: %s, finished: %s) agentRemove',
|
|
3953
|
-
socket[SOCKET_NAME],
|
|
3954
|
-
socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT]);
|
|
3955
|
-
// We need this function for cases like HTTP 'upgrade'
|
|
3956
|
-
// (defined by WebSockets) where we need to remove a socket from the
|
|
3957
|
-
// pool because it'll be locked up indefinitely
|
|
3958
|
-
socket.removeListener('close', onClose);
|
|
3959
|
-
socket.removeListener('error', onError);
|
|
3960
|
-
socket.removeListener('free', onFree);
|
|
3961
|
-
socket.removeListener('timeout', onTimeout);
|
|
3962
|
-
socket.removeListener('agentRemove', onRemove);
|
|
3963
|
-
}
|
|
3964
|
-
socket.on('agentRemove', onRemove);
|
|
4002
|
+
function inspect(obj) {
|
|
4003
|
+
const res = {};
|
|
4004
|
+
for (const key in obj) {
|
|
4005
|
+
res[key] = obj[key].length;
|
|
4006
|
+
}
|
|
4007
|
+
return res;
|
|
4008
|
+
}
|
|
4009
|
+
return agent;
|
|
3965
4010
|
}
|
|
3966
4011
|
|
|
3967
|
-
var
|
|
4012
|
+
var https_agent;
|
|
4013
|
+
var hasRequiredHttps_agent;
|
|
4014
|
+
|
|
4015
|
+
function requireHttps_agent () {
|
|
4016
|
+
if (hasRequiredHttps_agent) return https_agent;
|
|
4017
|
+
hasRequiredHttps_agent = 1;
|
|
4018
|
+
|
|
4019
|
+
const OriginalHttpsAgent = require$$0$2.Agent;
|
|
4020
|
+
const HttpAgent = /*@__PURE__*/ requireAgent();
|
|
4021
|
+
const {
|
|
4022
|
+
INIT_SOCKET,
|
|
4023
|
+
CREATE_HTTPS_CONNECTION,
|
|
4024
|
+
} = /*@__PURE__*/ requireConstants();
|
|
4025
|
+
|
|
4026
|
+
class HttpsAgent extends HttpAgent {
|
|
4027
|
+
constructor(options) {
|
|
4028
|
+
super(options);
|
|
4029
|
+
|
|
4030
|
+
this.defaultPort = 443;
|
|
4031
|
+
this.protocol = 'https:';
|
|
4032
|
+
this.maxCachedSessions = this.options.maxCachedSessions;
|
|
4033
|
+
/* istanbul ignore next */
|
|
4034
|
+
if (this.maxCachedSessions === undefined) {
|
|
4035
|
+
this.maxCachedSessions = 100;
|
|
4036
|
+
}
|
|
4037
|
+
|
|
4038
|
+
this._sessionCache = {
|
|
4039
|
+
map: {},
|
|
4040
|
+
list: [],
|
|
4041
|
+
};
|
|
4042
|
+
}
|
|
4043
|
+
|
|
4044
|
+
createConnection(options, oncreate) {
|
|
4045
|
+
const socket = this[CREATE_HTTPS_CONNECTION](options, oncreate);
|
|
4046
|
+
this[INIT_SOCKET](socket, options);
|
|
4047
|
+
return socket;
|
|
4048
|
+
}
|
|
4049
|
+
}
|
|
3968
4050
|
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
4051
|
+
// https://github.com/nodejs/node/blob/master/lib/https.js#L89
|
|
4052
|
+
HttpsAgent.prototype[CREATE_HTTPS_CONNECTION] = OriginalHttpsAgent.prototype.createConnection;
|
|
4053
|
+
|
|
4054
|
+
[
|
|
4055
|
+
'getName',
|
|
4056
|
+
'_getSession',
|
|
4057
|
+
'_cacheSession',
|
|
4058
|
+
// https://github.com/nodejs/node/pull/4982
|
|
4059
|
+
'_evictSession',
|
|
4060
|
+
].forEach(function(method) {
|
|
4061
|
+
/* istanbul ignore next */
|
|
4062
|
+
if (typeof OriginalHttpsAgent.prototype[method] === 'function') {
|
|
4063
|
+
HttpsAgent.prototype[method] = OriginalHttpsAgent.prototype[method];
|
|
4064
|
+
}
|
|
4065
|
+
});
|
|
4066
|
+
|
|
4067
|
+
https_agent = HttpsAgent;
|
|
4068
|
+
return https_agent;
|
|
3975
4069
|
}
|
|
3976
4070
|
|
|
3977
|
-
|
|
3978
|
-
const HttpAgent = agent;
|
|
3979
|
-
const {
|
|
3980
|
-
INIT_SOCKET,
|
|
3981
|
-
CREATE_HTTPS_CONNECTION,
|
|
3982
|
-
} = constants;
|
|
3983
|
-
|
|
3984
|
-
let HttpsAgent$1 = class HttpsAgent extends HttpAgent {
|
|
3985
|
-
constructor(options) {
|
|
3986
|
-
super(options);
|
|
3987
|
-
|
|
3988
|
-
this.defaultPort = 443;
|
|
3989
|
-
this.protocol = 'https:';
|
|
3990
|
-
this.maxCachedSessions = this.options.maxCachedSessions;
|
|
3991
|
-
/* istanbul ignore next */
|
|
3992
|
-
if (this.maxCachedSessions === undefined) {
|
|
3993
|
-
this.maxCachedSessions = 100;
|
|
3994
|
-
}
|
|
3995
|
-
|
|
3996
|
-
this._sessionCache = {
|
|
3997
|
-
map: {},
|
|
3998
|
-
list: [],
|
|
3999
|
-
};
|
|
4000
|
-
}
|
|
4001
|
-
|
|
4002
|
-
createConnection(options, oncreate) {
|
|
4003
|
-
const socket = this[CREATE_HTTPS_CONNECTION](options, oncreate);
|
|
4004
|
-
this[INIT_SOCKET](socket, options);
|
|
4005
|
-
return socket;
|
|
4006
|
-
}
|
|
4007
|
-
};
|
|
4008
|
-
|
|
4009
|
-
// https://github.com/nodejs/node/blob/master/lib/https.js#L89
|
|
4010
|
-
HttpsAgent$1.prototype[CREATE_HTTPS_CONNECTION] = OriginalHttpsAgent.prototype.createConnection;
|
|
4011
|
-
|
|
4012
|
-
[
|
|
4013
|
-
'getName',
|
|
4014
|
-
'_getSession',
|
|
4015
|
-
'_cacheSession',
|
|
4016
|
-
// https://github.com/nodejs/node/pull/4982
|
|
4017
|
-
'_evictSession',
|
|
4018
|
-
].forEach(function(method) {
|
|
4019
|
-
/* istanbul ignore next */
|
|
4020
|
-
if (typeof OriginalHttpsAgent.prototype[method] === 'function') {
|
|
4021
|
-
HttpsAgent$1.prototype[method] = OriginalHttpsAgent.prototype[method];
|
|
4022
|
-
}
|
|
4023
|
-
});
|
|
4071
|
+
var hasRequiredAgentkeepalive;
|
|
4024
4072
|
|
|
4025
|
-
|
|
4073
|
+
function requireAgentkeepalive () {
|
|
4074
|
+
if (hasRequiredAgentkeepalive) return agentkeepalive.exports;
|
|
4075
|
+
hasRequiredAgentkeepalive = 1;
|
|
4026
4076
|
|
|
4027
|
-
agentkeepalive.exports =
|
|
4028
|
-
|
|
4029
|
-
agentkeepalive.exports.constants =
|
|
4077
|
+
agentkeepalive.exports = /*@__PURE__*/ requireAgent();
|
|
4078
|
+
agentkeepalive.exports.HttpsAgent = /*@__PURE__*/ requireHttps_agent();
|
|
4079
|
+
agentkeepalive.exports.constants = /*@__PURE__*/ requireConstants();
|
|
4080
|
+
return agentkeepalive.exports;
|
|
4081
|
+
}
|
|
4030
4082
|
|
|
4031
|
-
var agentkeepaliveExports =
|
|
4083
|
+
var agentkeepaliveExports = /*@__PURE__*/ requireAgentkeepalive();
|
|
4032
4084
|
var HttpKeepAliveAgent = /*@__PURE__*/getDefaultExportFromCjs(agentkeepaliveExports);
|
|
4033
4085
|
|
|
4034
|
-
var
|
|
4035
|
-
var
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4086
|
+
var fastStableStringify$1;
|
|
4087
|
+
var hasRequiredFastStableStringify;
|
|
4088
|
+
|
|
4089
|
+
function requireFastStableStringify () {
|
|
4090
|
+
if (hasRequiredFastStableStringify) return fastStableStringify$1;
|
|
4091
|
+
hasRequiredFastStableStringify = 1;
|
|
4092
|
+
var objToString = Object.prototype.toString;
|
|
4093
|
+
var objKeys = Object.keys || function(obj) {
|
|
4094
|
+
var keys = [];
|
|
4095
|
+
for (var name in obj) {
|
|
4096
|
+
keys.push(name);
|
|
4097
|
+
}
|
|
4098
|
+
return keys;
|
|
4099
|
+
};
|
|
4042
4100
|
|
|
4043
|
-
function stringify(val, isArrayProp) {
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4101
|
+
function stringify(val, isArrayProp) {
|
|
4102
|
+
var i, max, str, keys, key, propVal, toStr;
|
|
4103
|
+
if (val === true) {
|
|
4104
|
+
return "true";
|
|
4105
|
+
}
|
|
4106
|
+
if (val === false) {
|
|
4107
|
+
return "false";
|
|
4108
|
+
}
|
|
4109
|
+
switch (typeof val) {
|
|
4110
|
+
case "object":
|
|
4111
|
+
if (val === null) {
|
|
4112
|
+
return null;
|
|
4113
|
+
} else if (val.toJSON && typeof val.toJSON === "function") {
|
|
4114
|
+
return stringify(val.toJSON(), isArrayProp);
|
|
4115
|
+
} else {
|
|
4116
|
+
toStr = objToString.call(val);
|
|
4117
|
+
if (toStr === "[object Array]") {
|
|
4118
|
+
str = '[';
|
|
4119
|
+
max = val.length - 1;
|
|
4120
|
+
for(i = 0; i < max; i++) {
|
|
4121
|
+
str += stringify(val[i], true) + ',';
|
|
4122
|
+
}
|
|
4123
|
+
if (max > -1) {
|
|
4124
|
+
str += stringify(val[i], true);
|
|
4125
|
+
}
|
|
4126
|
+
return str + ']';
|
|
4127
|
+
} else if (toStr === "[object Object]") {
|
|
4128
|
+
// only object is left
|
|
4129
|
+
keys = objKeys(val).sort();
|
|
4130
|
+
max = keys.length;
|
|
4131
|
+
str = "";
|
|
4132
|
+
i = 0;
|
|
4133
|
+
while (i < max) {
|
|
4134
|
+
key = keys[i];
|
|
4135
|
+
propVal = stringify(val[key], false);
|
|
4136
|
+
if (propVal !== undefined) {
|
|
4137
|
+
if (str) {
|
|
4138
|
+
str += ',';
|
|
4139
|
+
}
|
|
4140
|
+
str += JSON.stringify(key) + ':' + propVal;
|
|
4081
4141
|
}
|
|
4082
|
-
|
|
4142
|
+
i++;
|
|
4083
4143
|
}
|
|
4084
|
-
|
|
4144
|
+
return '{' + str + '}';
|
|
4145
|
+
} else {
|
|
4146
|
+
return JSON.stringify(val);
|
|
4085
4147
|
}
|
|
4086
|
-
return '{' + str + '}';
|
|
4087
|
-
} else {
|
|
4088
|
-
return JSON.stringify(val);
|
|
4089
4148
|
}
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4149
|
+
case "function":
|
|
4150
|
+
case "undefined":
|
|
4151
|
+
return isArrayProp ? null : undefined;
|
|
4152
|
+
case "string":
|
|
4153
|
+
return JSON.stringify(val);
|
|
4154
|
+
default:
|
|
4155
|
+
return isFinite(val) ? val : null;
|
|
4156
|
+
}
|
|
4098
4157
|
}
|
|
4099
|
-
}
|
|
4100
4158
|
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
};
|
|
4159
|
+
fastStableStringify$1 = function(val) {
|
|
4160
|
+
var returnVal = stringify(val, false);
|
|
4161
|
+
if (returnVal !== undefined) {
|
|
4162
|
+
return ''+ returnVal;
|
|
4163
|
+
}
|
|
4164
|
+
};
|
|
4165
|
+
return fastStableStringify$1;
|
|
4166
|
+
}
|
|
4107
4167
|
|
|
4108
|
-
var
|
|
4168
|
+
var fastStableStringifyExports = /*@__PURE__*/ requireFastStableStringify();
|
|
4169
|
+
var fastStableStringify = /*@__PURE__*/getDefaultExportFromCjs(fastStableStringifyExports);
|
|
4109
4170
|
|
|
4110
4171
|
const MINIMUM_SLOT_PER_EPOCH = 32;
|
|
4111
4172
|
|
|
@@ -4930,7 +4991,7 @@ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disable
|
|
|
4930
4991
|
maxSockets: 25
|
|
4931
4992
|
};
|
|
4932
4993
|
if (url.startsWith('https:')) {
|
|
4933
|
-
agent = new HttpsAgent(agentOptions);
|
|
4994
|
+
agent = new agentkeepaliveExports.HttpsAgent(agentOptions);
|
|
4934
4995
|
} else {
|
|
4935
4996
|
agent = new HttpKeepAliveAgent(agentOptions);
|
|
4936
4997
|
}
|
|
@@ -4938,9 +4999,9 @@ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disable
|
|
|
4938
4999
|
} else {
|
|
4939
5000
|
if (httpAgent !== false) {
|
|
4940
5001
|
const isHttps = url.startsWith('https:');
|
|
4941
|
-
if (isHttps && !(httpAgent instanceof Agent
|
|
5002
|
+
if (isHttps && !(httpAgent instanceof Agent)) {
|
|
4942
5003
|
throw new Error('The endpoint `' + url + '` can only be paired with an `https.Agent`. You have, instead, supplied an ' + '`http.Agent` through `httpAgent`.');
|
|
4943
|
-
} else if (!isHttps && httpAgent instanceof Agent
|
|
5004
|
+
} else if (!isHttps && httpAgent instanceof Agent) {
|
|
4944
5005
|
throw new Error('The endpoint `' + url + '` can only be paired with an `http.Agent`. You have, instead, supplied an ' + '`https.Agent` through `httpAgent`.');
|
|
4945
5006
|
}
|
|
4946
5007
|
agent = httpAgent;
|
|
@@ -5990,7 +6051,7 @@ class Connection {
|
|
|
5990
6051
|
config
|
|
5991
6052
|
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
5992
6053
|
const args = this._buildArgs([], commitment, undefined /* encoding */, config);
|
|
5993
|
-
const requestHash = fastStableStringify
|
|
6054
|
+
const requestHash = fastStableStringify(args);
|
|
5994
6055
|
requestPromises[requestHash] = requestPromises[requestHash] ?? (async () => {
|
|
5995
6056
|
try {
|
|
5996
6057
|
const unsafeRes = await this._rpcRequest('getBlockHeight', args);
|
|
@@ -8309,9 +8370,10 @@ class Connection {
|
|
|
8309
8370
|
this._subscriptionCallbacksByServerSubscriptionId[serverSubscriptionId] = subscription.callbacks;
|
|
8310
8371
|
await this._updateSubscriptions();
|
|
8311
8372
|
} catch (e) {
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8373
|
+
console.error(`Received ${e instanceof Error ? '' : 'JSON-RPC '}error calling \`${method}\``, {
|
|
8374
|
+
args,
|
|
8375
|
+
error: e
|
|
8376
|
+
});
|
|
8315
8377
|
if (!isCurrentConnectionStillActive()) {
|
|
8316
8378
|
return;
|
|
8317
8379
|
}
|
|
@@ -8447,7 +8509,7 @@ class Connection {
|
|
|
8447
8509
|
*/
|
|
8448
8510
|
args) {
|
|
8449
8511
|
const clientSubscriptionId = this._nextClientSubscriptionId++;
|
|
8450
|
-
const hash = fastStableStringify
|
|
8512
|
+
const hash = fastStableStringify([subscriptionConfig.method, args]);
|
|
8451
8513
|
const existingSubscription = this._subscriptionsByHash[hash];
|
|
8452
8514
|
if (existingSubscription === undefined) {
|
|
8453
8515
|
this._subscriptionsByHash[hash] = {
|