@eggjs/cluster 3.0.0-beta.3 → 3.0.0

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/src/master.ts CHANGED
@@ -4,6 +4,7 @@ import util from 'node:util';
4
4
  import path from 'node:path';
5
5
  import fs from 'node:fs';
6
6
  import net from 'node:net';
7
+ import { debuglog } from 'node:util';
7
8
  import { ReadyEventEmitter } from 'get-ready';
8
9
  import { detectPort } from 'detect-port';
9
10
  import { reload } from 'cluster-reload';
@@ -23,6 +24,8 @@ import {
23
24
  import { AppThreadWorker, AppThreadUtils as WorkerThreadsAppWorker } from './utils/mode/impl/worker_threads/app.js';
24
25
  import { ClusterWorkerExceptionError } from './error/ClusterWorkerExceptionError.js';
25
26
 
27
+ const debug = debuglog('@eggjs/cluster/master');
28
+
26
29
  export interface MasterOptions extends ParsedClusterOptions {
27
30
  clusterPort?: number;
28
31
  stickyWorkerPort?: number;
@@ -79,7 +82,7 @@ export class Master extends ReadyEventEmitter {
79
82
  this.startByProcess();
80
83
  }
81
84
 
82
- this.log(`[master] =================== ${frameworkPkg.name} start =====================`);
85
+ this.log(`[master] =================== ${frameworkPkg.name} start 🥚🥚🥚🥚 =====================`);
83
86
  this.logger.info(`[master] node version ${process.version}`);
84
87
  /* istanbul ignore next */
85
88
  if ('alinode' in process) {
@@ -153,7 +156,7 @@ export class Master extends ReadyEventEmitter {
153
156
  // get the real port from options and app.config
154
157
  // app worker will send after loading
155
158
  this.on('realport', ({ port, protocol }) => {
156
- this.logger.info('[master] got realport: %s, protocol: %s', port, protocol);
159
+ // this.logger.info('[master] got realport: %s, protocol: %s', port, protocol);
157
160
  if (port) {
158
161
  this.#realPort = port;
159
162
  }
@@ -455,7 +458,7 @@ export class Master extends ReadyEventEmitter {
455
458
  address: ListeningAddress;
456
459
  }) {
457
460
  const worker = this.workerManager.getWorker(data.workerId)!;
458
- this.log('[master] got app_worker#%s:%s app-start event, data: %j', worker.id, worker.workerId, data);
461
+ debug('got app_worker#%s:%s app-start event, data: %j', worker.id, worker.workerId, data);
459
462
 
460
463
  const address = data.address;
461
464
  // worker should listen stickyWorkerPort when sticky mode
@@ -637,14 +640,17 @@ function getAddress({
637
640
  return address!;
638
641
  }
639
642
 
640
- let hostname = address;
641
- if (!hostname && process.env.HOST && process.env.HOST !== '0.0.0.0') {
642
- hostname = process.env.HOST;
643
+ // {"address":"::","family":"IPv6","port":17001}
644
+ if (address === '::') {
645
+ address = '';
646
+ }
647
+ if (!address && process.env.HOST && process.env.HOST !== '0.0.0.0') {
648
+ address = process.env.HOST;
643
649
  }
644
- if (!hostname) {
645
- hostname = '127.0.0.1';
650
+ if (!address) {
651
+ address = '127.0.0.1';
646
652
  }
647
- return `${protocol}://${hostname}:${port}`;
653
+ return `${protocol}://${address}:${port}`;
648
654
  }
649
655
 
650
656
  function isUnixSock(address: ListeningAddress) {