Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

think-cluster

Package Overview
Dependencies
Maintainers
5
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

think-cluster - npm Package Compare versions

Comparing version 1.0.10 to 1.0.11

0

index.d.ts

@@ -0,0 +0,0 @@ // Type definitions for think-cluster in ThinkJs 3.x

22

lib/worker.js

@@ -5,3 +5,3 @@ const util = require('./util.js');

const AgentClient = require('./agent_client.js');
const debug = require('debug')('think-cluster');
const KEEP_ALIVE = Symbol('think-graceful-keepalive');

@@ -18,4 +18,4 @@

logger: () => {},
onUncaughtException: () => false, // onUncaughtException event handle
onUnhandledRejection: () => false, // onUnhandledRejection event handle
onUncaughtException: () => true, // onUncaughtException event handle
onUnhandledRejection: () => true, // onUnhandledRejection event handle
processKillTimeout: 10 * 1000 // 10s

@@ -41,4 +41,3 @@ };

this[KEEP_ALIVE] = true;
const server = this.options.server;
server.on('request', (req, res) => {
this.server.on('request', (req, res) => {
req.shouldKeepAlive = false;

@@ -56,8 +55,6 @@ res.shouldKeepAlive = false;

this.disableKeepAlive();
const logger = this.options.logger;
const killTimeout = this.options.processKillTimeout;
if (killTimeout) {
const timer = setTimeout(() => {
logger(`process exit by killed(timeout: ${killTimeout}ms), pid: ${process.pid}`);
debug(`process exit by killed(timeout: ${killTimeout}ms), pid: ${process.pid}`);
process.exit(1);

@@ -68,10 +65,9 @@ }, killTimeout);

const worker = cluster.worker;
const server = this.options.server;
logger(`start close server, pid: ${process.pid}, connections: ${server._connections}`);
server.close(() => {
logger(`server closed, pid: ${process.pid}`);
debug(`start close server, pid: ${process.pid}`);
this.server.close(() => {
debug(`server closed, pid: ${process.pid}`);
try {
worker.disconnect();
} catch (e) {
logger(`already disconnect, pid:${process.pid}`);
debug(`already disconnect, pid:${process.pid}`);
}

@@ -78,0 +74,0 @@ });

{
"name": "think-cluster",
"description": "Cluster manage for ThinkJS",
"version": "1.0.10",
"version": "1.0.11",
"author": {

@@ -6,0 +6,0 @@ "name": "welefen",

@@ -53,38 +53,38 @@ const test = require('ava');

// test.serial('options.workers >= 2 && enableAgent is true', async t => {
// try {
// let result = {};
// let options = {
// workers: 2,
// reloadSignal: 'SIGUSR2',
// enableAgent: true
// };
// executeProcess('master.js', options,'forkWorkers', (output) => {
// Object.assign(result, output);
// });
// await sleep(interval);
// t.is(result.isForked, true);
// t.is(result.options.enableAgent, true);
// } catch (e) {
// }
// });
test.serial('options.workers >= 2 && enableAgent is true', async t => {
try {
let result = {};
let options = {
workers: 2,
reloadSignal: 'SIGUSR2',
enableAgent: true
};
executeProcess('master.js', options,'forkWorkers', (output) => {
Object.assign(result, output);
});
await sleep(interval);
t.is(result.isForked, true);
t.is(result.options.enableAgent, true);
} catch (e) {
}
});
// test.serial('if options.workers < 2,enableAgent is false', async t => {
// try {
// let result = {};
// let options = {
// workers: 1,
// reloadSignal: 'SIGUSR2',
// enableAgent: true
// };
// executeProcess('master.js', options,'forkWorkers', (output) => {
// Object.assign(result, output);
// });
// await sleep(interval);
// t.is(result.isForked, true);
// // if workers < 2, set enableAgent false
// t.is(result.options.enableAgent, false);
// } catch (e) {
// }
// });
test.serial('if options.workers < 2,enableAgent is false', async t => {
try {
let result = {};
let options = {
workers: 1,
reloadSignal: 'SIGUSR2',
enableAgent: true
};
executeProcess('master.js', options,'forkWorkers', (output) => {
Object.assign(result, output);
});
await sleep(interval);
t.is(result.isForked, true);
// if workers < 2, set enableAgent false
t.is(result.options.enableAgent, false);
} catch (e) {
}
});

@@ -104,28 +104,28 @@ test.serial('reloadWorkers', async t => {

// test.serial('trigger SIGUSR2 signal', async t => {
// try {
// let result = {};
// let options = {
// reloadSignal: 'SIGUSR2',
// };
// let masterProcess = executeProcess('master.js', options,'forkWorkers', (output) => {
// Object.assign(result, output);
// });
// await sleep(interval);
// t.is(result.isForked, true);
// console.log(`master process id is ${masterProcess.pid}`);
// await sleep(interval);
test.serial('trigger SIGUSR2 signal', async t => {
try {
let result = {};
let options = {
reloadSignal: 'SIGUSR2',
};
let masterProcess = executeProcess('master.js', options,'forkWorkers', (output) => {
Object.assign(result, output);
});
await sleep(interval);
t.is(result.isForked, true);
console.log(`master process id is ${masterProcess.pid}`);
await sleep(interval);
// exec(`KILL -SIGUSR2 ${masterProcess.pid}`,{shell:'/bin/sh'},(error, stdout, stderr)=>{
// console.log(`stdout: ${stdout}`);
// console.log(`stderr: ${stderr}`);
// if (error !== null) {
// console.log(`exec error: ${error}`);
// }
// });
// await sleep(interval);
exec(`KILL -SIGUSR2 ${masterProcess.pid}`,{shell:'/bin/sh'},(error, stdout, stderr)=>{
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});
await sleep(interval);
// } catch (e) {
// }
// });
} catch (e) {
}
});

@@ -132,0 +132,0 @@ test.serial('trigger worker unHandleRejection ', async t => {

@@ -108,2 +108,10 @@ const test = require('ava');

test.serial('normal case', async t => {
mockCluster();
const cluster = require('cluster');
const Master = getMaster();
let instance = new Master({reloadSignal:'SIGUSR2'});
await instance.forkWorkers();
await process.kill(process.pid,'SIGUSR2');
});

@@ -110,0 +118,0 @@ test.serial('normal case', async t => {

@@ -122,3 +122,3 @@ const test = require('ava');

test.serial('normal case', async t => {
test.serial('normal case 7', async t => {
let unhandledRejectionDid = false;

@@ -160,3 +160,3 @@ const config = {

test.serial('normal case', async t => {
test.serial('normal case 8', async t => {
mockCluster();

@@ -191,2 +191,3 @@

let instance = new Worker(config);
instance.server = config.server;
cluster.fork();

@@ -196,2 +197,3 @@ instance.disconnectWorker(true);

config.server.trigger('request')

@@ -202,3 +204,3 @@ t.is(config.server.res.Connection,'close');

test.serial('normal case', async t => {
test.serial('normal case 3', async t => {
mockProcess();

@@ -235,2 +237,3 @@ mockCluster();

let instance = new Worker(config);
instance.server = config.server;
cluster.fork();

@@ -240,3 +243,3 @@ instance.disconnectWorker(false);

test.serial('normal case', async t => {
test.serial('normal case 2', async t => {
mockCluster();

@@ -386,3 +389,3 @@

test.serial('closeServer case', async t => {
test.serial('closeServer case 1', async t => {
mockCluster();

@@ -413,2 +416,3 @@ mockProcess();

let instance = new Worker(config);
instance.server = config.server;

@@ -422,3 +426,3 @@ instance.closeServer();

test.serial('closeServer case', async t => {
test.serial('closeServer case 4', async t => {
mockCluster();

@@ -450,2 +454,3 @@ mockProcess();

let instance = new Worker(config);
instance.server = config.server;

@@ -459,3 +464,3 @@ instance.closeServer();

test.serial('closeServer case', async t => {
test.serial('closeServer case 2', async t => {
mockCluster();

@@ -487,2 +492,3 @@ mockProcess();

let instance = new Worker(config);
instance.server = config.server;

@@ -496,3 +502,3 @@ instance.closeServer();

test.serial('closeServer case', async t => {
test.serial('closeServer case 3', async t => {
mockCluster();

@@ -525,2 +531,3 @@ mockProcess();

let instance = new Worker(config);
instance.server = config.server;

@@ -534,3 +541,3 @@ instance.closeServer();

test.serial('closeServer case', async t => {
test.serial('closeServer case 5', async t => {
mockCluster();

@@ -537,0 +544,0 @@ mockProcess();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc