livedesk 0.1.125 → 0.1.126
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/hub/src/remote-hub.js +52 -13
- package/hub/src/server.js +1 -1
- package/package.json +1 -1
package/hub/src/remote-hub.js
CHANGED
|
@@ -1339,7 +1339,9 @@ export function createRemoteHub(options = {}) {
|
|
|
1339
1339
|
const inputSockets = new Map();
|
|
1340
1340
|
const frameSockets = new Map();
|
|
1341
1341
|
const allSockets = new Set();
|
|
1342
|
+
const agentBinaryIngressLanes = [];
|
|
1342
1343
|
const duplicateDeviceLogAt = new Map();
|
|
1344
|
+
let agentBinaryIngressDraining = false;
|
|
1343
1345
|
let server = null;
|
|
1344
1346
|
let started = false;
|
|
1345
1347
|
let boundPort = requestedPort;
|
|
@@ -3305,29 +3307,56 @@ export function createRemoteHub(options = {}) {
|
|
|
3305
3307
|
state.binaryQueueDrops = Number(state.binaryQueueDrops || 0) + 1;
|
|
3306
3308
|
}
|
|
3307
3309
|
|
|
3308
|
-
function
|
|
3309
|
-
if (state
|
|
3310
|
+
function scheduleAgentBinaryIngress(socket, state) {
|
|
3311
|
+
if (!state || state.closed || !socket || socket.destroyed) {
|
|
3310
3312
|
return;
|
|
3311
3313
|
}
|
|
3312
|
-
state.binaryQueueDraining = true;
|
|
3313
|
-
setImmediate(() => {
|
|
3314
|
-
state.binaryQueueDraining = false;
|
|
3315
|
-
if (state.closed || socket.destroyed) {
|
|
3316
|
-
state.binaryQueue.length = 0;
|
|
3317
|
-
return;
|
|
3318
|
-
}
|
|
3319
3314
|
|
|
3315
|
+
state.binaryQueueSocket = socket;
|
|
3316
|
+
if (state.binaryQueueScheduled !== true) {
|
|
3317
|
+
state.binaryQueueScheduled = true;
|
|
3318
|
+
agentBinaryIngressLanes.push(state);
|
|
3319
|
+
}
|
|
3320
|
+
drainAgentBinaryIngressRoundRobin();
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
function drainAgentBinaryIngressRoundRobin() {
|
|
3324
|
+
if (agentBinaryIngressDraining) {
|
|
3325
|
+
return;
|
|
3326
|
+
}
|
|
3327
|
+
agentBinaryIngressDraining = true;
|
|
3328
|
+
setImmediate(() => {
|
|
3329
|
+
agentBinaryIngressDraining = false;
|
|
3320
3330
|
let processed = 0;
|
|
3321
|
-
while (
|
|
3331
|
+
while (agentBinaryIngressLanes.length > 0 && processed < AGENT_BINARY_INGRESS_DRAIN_BUDGET_PACKETS) {
|
|
3332
|
+
const state = agentBinaryIngressLanes.shift();
|
|
3333
|
+
if (!state) {
|
|
3334
|
+
continue;
|
|
3335
|
+
}
|
|
3336
|
+
|
|
3337
|
+
state.binaryQueueScheduled = false;
|
|
3338
|
+
const socket = state.binaryQueueSocket;
|
|
3339
|
+
if (state.closed || !socket || socket.destroyed) {
|
|
3340
|
+
if (Array.isArray(state.binaryQueue)) {
|
|
3341
|
+
state.binaryQueue.length = 0;
|
|
3342
|
+
}
|
|
3343
|
+
continue;
|
|
3344
|
+
}
|
|
3345
|
+
|
|
3322
3346
|
const item = state.binaryQueue.shift();
|
|
3323
3347
|
if (item) {
|
|
3324
3348
|
handleAgentBinaryFrame(socket, state, item.header, item.payload);
|
|
3325
3349
|
processed += 1;
|
|
3326
3350
|
}
|
|
3351
|
+
|
|
3352
|
+
if (state.binaryQueue.length > 0 && !state.closed && !socket.destroyed) {
|
|
3353
|
+
state.binaryQueueScheduled = true;
|
|
3354
|
+
agentBinaryIngressLanes.push(state);
|
|
3355
|
+
}
|
|
3327
3356
|
}
|
|
3328
3357
|
|
|
3329
|
-
if (
|
|
3330
|
-
|
|
3358
|
+
if (agentBinaryIngressLanes.length > 0) {
|
|
3359
|
+
drainAgentBinaryIngressRoundRobin();
|
|
3331
3360
|
}
|
|
3332
3361
|
});
|
|
3333
3362
|
}
|
|
@@ -3343,7 +3372,7 @@ export function createRemoteHub(options = {}) {
|
|
|
3343
3372
|
dropQueuedAgentBinaryFrame(state);
|
|
3344
3373
|
}
|
|
3345
3374
|
state.binaryQueue.push({ header, payload });
|
|
3346
|
-
|
|
3375
|
+
scheduleAgentBinaryIngress(socket, state);
|
|
3347
3376
|
}
|
|
3348
3377
|
|
|
3349
3378
|
function handleAgentMessage(socket, state, message) {
|
|
@@ -3489,6 +3518,8 @@ export function createRemoteHub(options = {}) {
|
|
|
3489
3518
|
frameOnly: false,
|
|
3490
3519
|
binaryQueue: [],
|
|
3491
3520
|
binaryQueueDraining: false,
|
|
3521
|
+
binaryQueueScheduled: false,
|
|
3522
|
+
binaryQueueSocket: null,
|
|
3492
3523
|
binaryQueueDrops: 0,
|
|
3493
3524
|
closed: false
|
|
3494
3525
|
};
|
|
@@ -3541,6 +3572,8 @@ export function createRemoteHub(options = {}) {
|
|
|
3541
3572
|
const detach = reason => {
|
|
3542
3573
|
state.closed = true;
|
|
3543
3574
|
state.binaryQueue.length = 0;
|
|
3575
|
+
state.binaryQueueScheduled = false;
|
|
3576
|
+
state.binaryQueueSocket = null;
|
|
3544
3577
|
allSockets.delete(socket);
|
|
3545
3578
|
clearTimeout(helloTimer);
|
|
3546
3579
|
detachInputSocket(socket, reason);
|
|
@@ -3640,6 +3673,8 @@ export function createRemoteHub(options = {}) {
|
|
|
3640
3673
|
pendingBinaryFrame: null,
|
|
3641
3674
|
binaryQueue: [],
|
|
3642
3675
|
binaryQueueDraining: false,
|
|
3676
|
+
binaryQueueScheduled: false,
|
|
3677
|
+
binaryQueueSocket: null,
|
|
3643
3678
|
binaryQueueDrops: 0,
|
|
3644
3679
|
closed: false
|
|
3645
3680
|
};
|
|
@@ -3770,6 +3805,8 @@ export function createRemoteHub(options = {}) {
|
|
|
3770
3805
|
socket.on('close', () => {
|
|
3771
3806
|
state.closed = true;
|
|
3772
3807
|
state.binaryQueue.length = 0;
|
|
3808
|
+
state.binaryQueueScheduled = false;
|
|
3809
|
+
state.binaryQueueSocket = null;
|
|
3773
3810
|
allSockets.delete(socket);
|
|
3774
3811
|
clearTimeout(helloTimer);
|
|
3775
3812
|
detachInputSocket(socket);
|
|
@@ -3779,6 +3816,8 @@ export function createRemoteHub(options = {}) {
|
|
|
3779
3816
|
socket.on('error', err => {
|
|
3780
3817
|
state.closed = true;
|
|
3781
3818
|
state.binaryQueue.length = 0;
|
|
3819
|
+
state.binaryQueueScheduled = false;
|
|
3820
|
+
state.binaryQueueSocket = null;
|
|
3782
3821
|
allSockets.delete(socket);
|
|
3783
3822
|
clearTimeout(helloTimer);
|
|
3784
3823
|
detachInputSocket(socket, err?.message || 'socket-error');
|
package/hub/src/server.js
CHANGED
|
@@ -23,7 +23,7 @@ const httpHost = process.env.LIVEDESK_HUB_HTTP_HOST || '0.0.0.0';
|
|
|
23
23
|
const httpPort = Number(process.env.LIVEDESK_HUB_HTTP_PORT || process.env.PORT || 5179);
|
|
24
24
|
const frameBackpressureBytes = readPositiveIntegerEnv('LIVEDESK_FRAME_WS_BACKPRESSURE_BYTES', 16 * 1024 * 1024);
|
|
25
25
|
const frameClientQueuePackets = readPositiveIntegerEnv('LIVEDESK_FRAME_WS_QUEUE_PACKETS', 12);
|
|
26
|
-
const frameClientDrainBudgetPackets = readPositiveIntegerEnv('LIVEDESK_FRAME_WS_DRAIN_BUDGET_PACKETS',
|
|
26
|
+
const frameClientDrainBudgetPackets = readPositiveIntegerEnv('LIVEDESK_FRAME_WS_DRAIN_BUDGET_PACKETS', 8);
|
|
27
27
|
const frameClients = new Set();
|
|
28
28
|
const frameClientsByDeviceId = new Map();
|
|
29
29
|
const frameWildcardClients = new Set();
|