Socket
Socket
Sign inDemoInstall

stoppable

Package Overview
Dependencies
1
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    stoppable

```js const server = stoppable(http.createServer(handler)) server.stop() ```


Version published
Maintainers
1
Install size
494 kB
Created

Readme

Source

Stoppable

const server = stoppable(http.createServer(handler))
server.stop()

This module implements Node's server.close() in the way you probably expected it to work by default: It stops accepting new connections and closes existing, idle connections (including keep-alives) without killing requests that are in-flight.

Installation

yarn add stoppable

(or use npm)

Usage

constructor

stoppable(server, grace)

Decorates the server instance with a stop method. Returns the server instance, so can be chained, or can be run as a standalone statement.

  • server: Any HTTP or HTTPS Server instance
  • grace: Milliseconds to wait before force-closing connections

grace defaults to Infinity (don't force-close). If you want to immediately kill all sockets you can use a grace of 0.

stop()

server.stop(callback)

Closes the server.

  • callback: passed along to the existing server.close function to auto-register a 'close' event

Design decisions

  • Monkey patching generally sucks, but in this case it's the nicest API. Let's call it "decorating."
  • grace could be specified on stop, but it's better to match the existing server.close API.
  • Clients should be handled respectfully, so we aren't just destroying sockets, we're sending FIN packets first.
  • Any solution to this problem requires bookkeeping on every connection and request/response. We're doing a minimum of work on these "hot" code paths and delaying as much as possible to the actual stop method.

FAQs

Last updated on 21 May 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc