@scrypted/server 0.123.23 → 0.123.24

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.
@@ -1,3 +1,4 @@
1
+ import os from 'os';
1
2
  import type { ForkOptions } from '@scrypted/types';
2
3
  import { once } from 'events';
3
4
  import net from 'net';
@@ -39,7 +40,7 @@ function peerLifecycle(serializer: ReturnType<typeof createRpcDuplexSerializer>,
39
40
  socket.on('close', () => {
40
41
  peer.kill(`cluster ${type} closed`);
41
42
  });
42
- peer.killed.then(() => {
43
+ peer.killedSafe.finally(() => {
43
44
  socket.destroy();
44
45
  });
45
46
  }
@@ -121,7 +122,7 @@ export function startClusterClient(mainFilename: string) {
121
122
  try {
122
123
  await once(rawSocket, 'connect');
123
124
  }
124
- catch( e) {
125
+ catch (e) {
125
126
  continue;
126
127
  }
127
128
 
@@ -155,7 +156,7 @@ export function startClusterClient(mainFilename: string) {
155
156
  const auth: ClusterObject = {
156
157
  address: socket.localAddress,
157
158
  port: socket.localPort,
158
- id: undefined,
159
+ id: process.env.SCRYPTED_CLUSTER_ID || os.hostname(),
159
160
  proxyId: undefined,
160
161
  sourceKey: undefined,
161
162
  sha256: undefined,
@@ -209,17 +210,19 @@ export function startClusterClient(mainFilename: string) {
209
210
  runtimeWorker.on('error', e => {
210
211
  threadPeer.kill('worker error ' + e);
211
212
  });
212
- threadPeer.killed.catch(() => { }).finally(() => {
213
+ threadPeer.killedSafe.finally(() => {
213
214
  runtimeWorker.kill();
214
215
  });
215
216
  peerLiveness.waitKilled().catch(() => { }).finally(() => {
216
217
  threadPeer.kill('peer killed');
217
218
  });
218
219
  let getRemote: any;
220
+ let ping: any;
219
221
  try {
220
222
  const initializeCluster: InitializeCluster = await threadPeer.getParam('initializeCluster');
221
223
  await initializeCluster({ clusterId, clusterSecret });
222
224
  getRemote = await threadPeer.getParam('getRemote');
225
+ ping = await threadPeer.getParam('ping');
223
226
  }
224
227
  catch (e) {
225
228
  threadPeer.kill('cluster fork failed');
@@ -242,6 +245,7 @@ export function startClusterClient(mainFilename: string) {
242
245
  stdout: readStream(runtimeWorker.stdout),
243
246
  stderr: readStream(runtimeWorker.stderr),
244
247
  getRemote,
248
+ ping,
245
249
  };
246
250
  };
247
251
 
@@ -255,9 +259,12 @@ export function startClusterClient(mainFilename: string) {
255
259
  }
256
260
  catch (e) {
257
261
  peer.kill(e.message);
258
- socket.destroy();
259
262
  console.warn('Cluster client error:', localAddress, localPort, e);
260
263
  }
264
+ finally {
265
+ peer.kill();
266
+ socket.destroy();
267
+ }
261
268
  }
262
269
  })();
263
270
  }
@@ -279,6 +286,9 @@ export function createClusterServer(runtime: ScryptedRuntime, certificate: Retur
279
286
  const sha256 = computeClusterObjectHash(auth, runtime.clusterSecret);
280
287
  if (sha256 !== auth.sha256)
281
288
  throw new Error('cluster object hash mismatch');
289
+
290
+ peer.peerName = auth.id || `${socket.remoteAddress}`;
291
+
282
292
  // the remote address may be ipv6 prefixed so use a fuzzy match.
283
293
  // eg ::ffff:192.168.2.124
284
294
  if (!process.env.SCRYPTED_DISABLE_CLUSTER_SERVER_TRUST) {
@@ -291,7 +301,7 @@ export function createClusterServer(runtime: ScryptedRuntime, certificate: Retur
291
301
  forks: new Set(),
292
302
  };
293
303
  runtime.clusterWorkers.add(worker);
294
- peer.killed.then(() => {
304
+ peer.killedSafe.finally(() => {
295
305
  runtime.clusterWorkers.delete(worker);
296
306
  });
297
307
  socket.on('close', () => {