ranch_connection_drainer icon indicating copy to clipboard operation
ranch_connection_drainer copied to clipboard

Gracefully drain ranch connections (Cowboy / Plug / Phoenix servers)

DEPRECATED: plug_cowboy 2.3.0 includes Plug.Cowboy.Drainer, which largely replaces the functionality of this library.

RanchConnectionDrainer Hex pm

This mini library implements connection draining for servers that use Ranch (Cowboy, Plug, Phoenix, and maybe others).

Installation

This package can be installed by adding ranch_connection_drainer to your list of dependencies in mix.exs:

def deps do
  [
    {:ranch_connection_drainer, "~> 0.1.0"}
  ]
end

Then add {RanchConnectionDrainer, ranch_ref: my_ranch_ref, shutdown: my_drain_timeout} to your application supervisor directly under your phoenix endpoint.

Example:

children = [
  MyPhoenixProject.Endpoint,
  {RanchConnectionDrainer, ranch_ref: MyPhoenixProject.Endpoint.HTTP, shutdown: 30_000}
]
Supervisor.init(children, opts)

The format of ranch_ref is: [PhoenixEndpoint].[HTTP | HTTPS]. Please open an issue if this is unclear.