-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
closes #65 increase to avoid nodejs warning ``` MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [ClusterServer]. Use emitter.setMaxListeners() to increase limit ``` Co-authored-by: gaoquanzero <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,3 @@ jobs: | |
secrets: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
GIT_TOKEN: ${{ secrets.GIT_TOKEN }} | ||
with: | ||
checkTest: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,8 +69,9 @@ class ClusterServer extends Base { | |
* | ||
* @class | ||
* @param {Object} options | ||
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (macos-latest, 14)
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (macos-latest, 18)
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (macos-latest, 16)
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (macos-latest, 20)
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (ubuntu-latest, 16)
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (ubuntu-latest, 14)
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (ubuntu-latest, 18)
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (ubuntu-latest, 20)
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (windows-latest, 14)
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (windows-latest, 16)
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (windows-latest, 18)
Check warning on line 71 in lib/server.js GitHub Actions / Node.js / Test (windows-latest, 20)
|
||
* - {net.Server} server - the server | ||
* - {Number} port - the port | ||
* @param {net.Server} options.server - the server | ||
* @param {Number} options.port - the port | ||
* @param {Number} [options.maxListeners] maximum of listeners, default is 20 | ||
*/ | ||
constructor(options) { | ||
super(); | ||
|
@@ -88,6 +89,7 @@ class ClusterServer extends Base { | |
this._server.once('error', err => { | ||
this.emit('error', err); | ||
}); | ||
this.setMaxListeners(options.maxListeners || 20); | ||
} | ||
|
||
get isClosed() { | ||
|
@@ -164,9 +166,11 @@ class ClusterServer extends Base { | |
* | ||
* @param {String} name - the client name | ||
* @param {Number} port - the port | ||
* @param {Object} [options] - create instance options | ||
* @param {Number} [options.maxListeners] maximum of listeners, default is 20 | ||
* @return {ClusterServer} server | ||
*/ | ||
static async create(name, port) { | ||
static async create(name, port, options) { | ||
const key = `${name}@${port}`; | ||
if (typeof port !== 'number') { | ||
throw new Error(`[ClusterClient.server.create:${name}] port should be a number, but got ${JSON.stringify(port)}`); | ||
|
@@ -185,7 +189,7 @@ class ClusterServer extends Base { | |
// compete for the local port, if got => leader, otherwise follower | ||
try { | ||
const server = await claimServer(port); | ||
instance = new ClusterServer({ server, port }); | ||
instance = new ClusterServer({ server, port, ...options }); | ||
typeSet.add(key); | ||
serverMap.set(port, instance); | ||
return instance; | ||
|