All Projects → thedillonb → Http Shutdown

thedillonb / Http Shutdown

Licence: mit
Shutdown a Nodejs HTTP server gracefully by terminating the listening socket, then destroying all keep-alive idle sockets all while allowing in-flight requests to finish.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Http Shutdown

Clusterws Client Js
🔥 JavaScript Client for ClusterWS - lightweight, fast and powerful framework for building scalable WebSocket applications in Node.js.
Stars: ✭ 120 (-20.53%)
Mutual labels:  socket
Arduino Kicad Library
Arduino Shield schematic and footprint library for KiCad
Stars: ✭ 130 (-13.91%)
Mutual labels:  socket
Owasp Mth3l3m3nt Framework
OWASP Mth3l3m3nt Framework is a penetration testing aiding tool and exploitation framework. It fosters a principle of attack the web using the web as well as pentest on the go through its responsive interface.
Stars: ✭ 139 (-7.95%)
Mutual labels:  socket
Socket
Non-blocking socket and TLS functionality for PHP based on Amp.
Stars: ✭ 122 (-19.21%)
Mutual labels:  socket
Socketdemo
创建热点发送文件,让另一台手机连接热点接收文件
Stars: ✭ 129 (-14.57%)
Mutual labels:  socket
Pesocket
A C# Network Library.
Stars: ✭ 134 (-11.26%)
Mutual labels:  socket
Pytest Socket
Pytest Plugin to disable socket calls during tests
Stars: ✭ 117 (-22.52%)
Mutual labels:  socket
Nuxt Socket Io
Nuxt Socket IO - socket.io client and server module for Nuxt
Stars: ✭ 148 (-1.99%)
Mutual labels:  socket
Socketpushclient
最近项目中要求做推送,基于内网的。由于工期不是很紧,需求不是很严格,所以放弃了使用三方的推送框架,基于Socket自己写了消息推送功能(服务端+android端)。服务器端使用java,客户端使用Android。本人是做Android开发的,所以demo重点介绍客户端的一些代码,包括Socket的TCP长连接及发消息,Service如何不被轻易杀死,通过aidl实现界面实时与Service的通信,可以在界面上控制Socket的连接与断开以及发消息,并采用了Parcelable对象实现aidl传参
Stars: ✭ 129 (-14.57%)
Mutual labels:  socket
Gengineserver
netty4游戏服务端,依赖游戏核心包
Stars: ✭ 140 (-7.28%)
Mutual labels:  socket
Af ktls
Linux Kernel TLS/DTLS Module
Stars: ✭ 124 (-17.88%)
Mutual labels:  socket
Async Sockets Cpp
Simple thread-based asynchronous TCP & UDP Socket classes in C++.
Stars: ✭ 127 (-15.89%)
Mutual labels:  socket
At device
AT component porting or samples for different devices
Stars: ✭ 136 (-9.93%)
Mutual labels:  socket
Go Netstat
A netstat implementation written in Go
Stars: ✭ 121 (-19.87%)
Mutual labels:  socket
Usocket
Universal socket library for Common Lisp
Stars: ✭ 146 (-3.31%)
Mutual labels:  socket
Tcpdog
eBPF based TCP observability.
Stars: ✭ 119 (-21.19%)
Mutual labels:  socket
Jstp
Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
Stars: ✭ 132 (-12.58%)
Mutual labels:  socket
Easysocket
一个轻量级的Android端Socket框架,可快速实现客户端和服务端之间的TCP长连接通讯,兼容于各种消息协议,框架的特色之一是可以实现Socket的消息回调功能
Stars: ✭ 148 (-1.99%)
Mutual labels:  socket
Ether.network
https://github.com/Eastrall/Sylver
Stars: ✭ 147 (-2.65%)
Mutual labels:  socket
Kuaichuan
仿茄子快传的一款文件传输应用
Stars: ✭ 1,727 (+1043.71%)
Mutual labels:  socket

Http-Shutdown NPM version Build status Test coverage

Shutdown a Nodejs HTTP server gracefully by doing the following:

  1. Close the listening socket to prevent new connections
  2. Close all idle keep-alive sockets to prevent new requests during shutdown
  3. Wait for all in-flight requests to finish before closing their sockets.
  4. Profit!

Other solutions might just use server.close which only terminates the listening socket and waits for other sockets to close - which is incomplete since keep-alive sockets can still make requests. Or, they may use ref()/unref() to simply cause Nodejs to terminate if the sockets are idle - which doesn't help if you have other things to shutdown after the server shutsdown.

http-shutdown is a complete solution. It uses idle indicators combined with an active socket list to safely, and gracefully, close all sockets. It does not use ref()/unref() but, instead, actively closes connections as they finish meaning that socket 'close' events still work correctly since the sockets are actually closing - you're not just unrefing and forgetting about them.

Installation

$ npm install http-shutdown

Usage

There are currently two ways to use this library. The first is explicit wrapping of the Server object:

// Create the http server
var server = require('http').createServer(function(req, res) {
  res.end('Good job!');
});

// Wrap the server object with additional functionality.
// This should be done immediately after server construction, or before you start listening.
// Additional functionailiy needs to be added for http server events to properly shutdown.
server = require('http-shutdown')(server);

// Listen on a port and start taking requests.
server.listen(3000);

// Sometime later... shutdown the server.
server.shutdown(function(err) {
	if (err) {
		return console.log('shutdown failed', err.message);
	}
	console.log('Everything is cleanly shutdown.');
});

The second is implicitly adding prototype functionality to the Server object:

// .extend adds a .withShutdown prototype method to the Server object
require('http-shutdown').extend();

var server = require('http').createServer(function(req, res) {
  res.end('God job!');
}).withShutdown(); // <-- Easy to chain. Returns the Server object

// Sometime later, shutdown the server.
server.shutdown(function(err) {
	if (err) {
		return console.log('shutdown failed', err.message);
	}
  console.log('Everything is cleanly shutdown.');
});

Test

$ npm test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].