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

lightship

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lightship - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

15

dist/factories/createLightship.js

@@ -10,2 +10,4 @@ "use strict";

var _serializeError = _interopRequireDefault(require("serialize-error"));
var _Logger = _interopRequireDefault(require("../Logger"));

@@ -93,6 +95,15 @@

for (const shutdownHandler of shutdownHandlers) {
await shutdownHandler();
try {
await shutdownHandler();
} catch (error) {
log.error({
error: (0, _serializeError.default)(error)
}, 'shutdown handler produced an error');
}
}
server.close();
log.debug('all shutdown handlers have run to completion; proceeding to terminate the Node.js process');
server.close(); // eslint-disable-next-line no-process-exit
process.exit();
};

@@ -99,0 +110,0 @@

5

package.json

@@ -38,3 +38,4 @@ {

"nyc": "^13.0.0",
"semantic-release": "^15.6.1"
"semantic-release": "^15.6.1",
"sinon": "^6.0.1"
},

@@ -78,3 +79,3 @@ "engines": {

},
"version": "1.1.0"
"version": "1.2.0"
}

@@ -91,3 +91,3 @@ <a name="lightship"></a>

*/
type BeforeShutdownHandlerType = () => Promise<void> | void;
type ShutdownHandlerType = () => Promise<void> | void;

@@ -104,2 +104,3 @@ /**

/**
* @property registerShutdownHandler Registers teardown functions that are called when shutdown is initialized. All registered shutdown handlers are executed in the order they have been registered. After all shutdown handlers have been executed, Lightship asks `process.exit()` to terminate the process synchronously.
* @property shutdown Changes server state to SERVER_IS_SHUTTING_DOWN and initialises the shutdown of the application.

@@ -110,3 +111,3 @@ * @property signalNotReady Changes server state to SERVER_IS_NOT_READY.

type LightshipType = {|
+registerShutdownHandler: (shutdownHandler: shutdownHandlerType) => void,
+registerShutdownHandler: (shutdownHandler: ShutdownHandlerType) => void,
+shutdown: () => Promise<void>,

@@ -308,5 +309,5 @@ +signalNotReady: () => void,

You don't need to kill Node.js in a shutdown handler, e.g. using `process.exit()`. Your Node.js service will exit when the [event loop](https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/)'s queue is empty, i.e. `server.close()` should be enough.
Do not call `process.exit()` in a shutdown handler – Lighthouse calls `process.exit()` after all registered shutdown handlers have run to completion.
Subject to the Pod's [restart policy](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy), Kubernetes will forcefully restart the Container after the `livenessProbe` deems the service to be failed.
If for whatever reason a registered shutdown handler hangs, then (subject to the Pod's [restart policy](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy)) Kubernetes will forcefully restart the Container after the `livenessProbe` deems the service to be failed.

@@ -313,0 +314,0 @@ <a name="lightship-faq"></a>

// @flow
import express from 'express';
import serializeError from 'serialize-error';
import Logger from '../Logger';

@@ -108,6 +109,17 @@ import type {

for (const shutdownHandler of shutdownHandlers) {
await shutdownHandler();
try {
await shutdownHandler();
} catch (error) {
log.error({
error: serializeError(error)
}, 'shutdown handler produced an error');
}
}
log.debug('all shutdown handlers have run to completion; proceeding to terminate the Node.js process');
server.close();
// eslint-disable-next-line no-process-exit
process.exit();
};

@@ -114,0 +126,0 @@

@@ -18,2 +18,3 @@ // @flow

/**
* @property registerShutdownHandler Registers teardown functions that are called when shutdown is initialized. All registered shutdown handlers are executed in the order they have been registered. After all shutdown handlers have been executed, Lightship asks `process.exit()` to terminate the process synchronously.
* @property shutdown Changes server state to SERVER_IS_SHUTTING_DOWN and initialises the shutdown of the application.

@@ -20,0 +21,0 @@ * @property signalNotReady Changes server state to SERVER_IS_NOT_READY.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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