ranch - Socket acceptor pool


The module ranch provides functions for starting and manipulating Ranch listeners.









max_conns() = non_neg_integer() | infinity

Maximum number of connections allowed per connection supervisor.

This is a soft limit. The actual number of connections might be slightly above the limit due to concurrency when accepting new connections. Some connections may also be removed from this count explicitly by the user code.


opts() = any() | transport_opts(any())

Transport or socket options.

It is possible to give the full transport options in a map (see transport_opts(SocketOpts)), or only the socket options (assuming they are not a map and no Ranch-specific option needs to be given).


ref() = any()

Unique name used to refer to a listener.


transport_opts(SocketOpts) = #{
    connection_type   => worker | supervisor,
    handshake_timeout => timeout(),
    max_connections   => max_conns(),
    logger            => module(),
    num_acceptors     => pos_integer(),
    num_conns_sups    => pos_integer(),
    shutdown          => timeout() | brutal_kill,
    socket_opts       => SocketOpts

Transport options.

The transport options are a combination of Ranch-specific options and transport-specific socket options.

None of the options are required.

connection_type (worker)

Type of process that will handle the connection.

handshake_timeout (5000)

Maximum allowed time for the ranch:handshake/1,2 call to finish.

logger (logger)

The module that will be used to write log messages.

max_connections (1024)

Maximum number of active connections per connection supervisor. Soft limit. Use infinity to disable the limit entirely.

num_acceptors (10)

Number of processes that accept connections.

num_conns_sups - see below

Number of processes that supervise connection processes. If not specified, defaults to be equal to num_acceptors.

shutdown (5000)

Maximum allowed time for children to stop on listener shutdown.


Socket options to be used by Transport:listen/1. Please refer to the documentation of the transport module you are using for more details.


  • 2.0: The type transport_opts(SocketOpts) was added.
  • 2.0: The function ranch:accept_ack/1 was removed in favor of ranch:handshake(3).
  • 2.0: The option max_connections is now per connection supervisor.
  • 2.0: The num_conns_sup option was added.
  • 2.0: The socket option was removed.
  • 2.0: The logger option is no longer experimental. It now defaults to logger instead of error_logger.
  • 2.0: The opt() type was removed.
  • 1.6: The experimental logger option was added.
  • 1.6: The opt() type was deprecated in favor of the new opts() type.

See also


Ranch 2.0 Function Reference


Version select

Like my work? Donate!

Donate to Loïc Hoguin because his work on Cowboy, Ranch, Gun and Erlang.mk is fantastic:

Recurring payment options are also available via GitHub Sponsors. These funds are used to cover the recurring expenses like food, dedicated servers or domain names.