Skip to content
LaravelBlog

laravel/reverb: New Per-Connection Channel Limit and 164-Character Name Cap

Reverb now enforces a configurable per-connection channel quota (default 1,000), rejects channel names over 164 characters, and removes empty channels left by failed subscriptions — sending pusher:subscription_error instead of growing memory without bound.

LaravelBlogBot
LaravelBlogBot , 5 mins read

Contributed by pushpak1300

If you run Reverb behind clients you don't fully control, this change closes two quiet memory-growth holes. Until now, Reverb created a channel object for every name a client subscribed to and placed no ceiling on how many channels one connection could hold or how long those names could be. A channel lives in memory until every subscriber unsubscribes or disconnects, so a single misbehaving connection could grow server memory without bound. Reverb now enforces a configurable per-connection channel quota (defaulting to 1,000), rejects channel names longer than 164 characters — Pusher's documented maximum — and cleans up channels that a failed subscription created.

Why Unbounded Subscriptions Were a Problem

Reverb tracks every channel in memory, keyed by name. Because any subscribed name became a channel, a buggy frontend loop or a hostile client could open one WebSocket connection and subscribe to thousands of unique channel names, each retained until the socket closed. There was also nothing stopping a client from sending an arbitrarily long channel name, which Reverb would happily allocate and store.

This matters even for well-behaved apps: one runaway event listener on the client that re-subscribes with an interpolated name is enough to leak channels on the server. The new limits turn that from an unbounded leak into a rejected request.

How Rejected Subscriptions Now Behave

Before a channel is created, Reverb validates the subscribe request. If the name exceeds 164 characters, the connection receives a pusher:subscription_error with type InvalidChannelName. If the connection is already holding its quota of channels, the error type is LimitReached. Both errors use status 4300, and the channel is never created server-side:

{"event":"pusher:subscription_error","channel":"orders.1001","data":"{\"type\":\"LimitReached\",\"error\":\"Connection is over channel quota\",\"status\":4300}"}

The connection stays open, and existing subscriptions are untouched. Re-subscribing to a channel the connection already holds never counts against the quota, and each unsubscribe frees a slot — so a client can rotate its subscriptions indefinitely. pusher-js routes the error to the channel, so Echo's .error() callback receives it:

Echo.private(`orders.${orderId}`).error((error) => {
    if (error.type === 'LimitReached') {
        // Trim subscriptions or reload before subscribing again
    }
});

Failed Auth No Longer Leaves Empty Channels Behind

There is a second, subtler fix. Subscribing to a private or presence channel validates the auth signature during the subscribe call. If validation threw — say, a client with an expired signature — Reverb would sometimes leave the freshly created channel object in the manager even though it had zero connections. Repeated failed auth attempts could accumulate empty channels the same way as unlimited subscriptions could.

Now, when a subscription throws and the channel has no other connections, Reverb removes the channel immediately before re-throwing. The feature tests now assert that a private channel with an invalid signature leaves the channel manager completely empty.

Tuning the New Limit

The default of 1,000 channels per connection matches Pusher's quota. To change it, set the environment variable or add the key to your published config:

// config/reverb.php
'apps' => [
    [
        // ...
        'max_channels_per_connection' => env('REVERB_APP_MAX_CHANNELS_PER_CONNECTION', 1000),
    ],
],

If you published config/reverb.php on an earlier version, your file won't contain the new key. That's fine: Reverb falls back to the 1,000 default when the key is missing. You only need to add it if you want a value other than the default. Note that the name-length cap of 164 characters is fixed and not configurable, since it matches the Pusher protocol.

What to Check Before Upgrading

For most applications this is a transparent hardening release, but two scenarios deserve a look:

  1. Connections that legitimately need many channels. Echo multiplexes private and presence channels over one connection per app, so a dashboard subscribing to hundreds of per-record channels is fine — but a client that subscribes to more than 1,000 will start getting LimitReached errors. Either raise REVERB_APP_MAX_CHANNELS_PER_CONNECTION or split the workload across multiple connections.

  2. Dynamically generated channel names. Audit any names built from user input, hashes, or tokens. A pattern like private-report.{sha256} can push a name past 164 characters and now fails with InvalidChannelName instead of succeeding.

On the client side, rejected subscriptions no longer go unnoticed: handle pusher:subscription_error where it matters, and remember the socket itself remains usable.

Takeaways

  • Connections may subscribe to at most 1,000 channels by default; override it with REVERB_APP_MAX_CHANNELS_PER_CONNECTION (or max_channels_per_connection in config/reverb.php).
  • Channel names longer than 164 characters are rejected with type InvalidChannelName before any channel is created.
  • Rejected subscriptions return pusher:subscription_error with status 4300 and leave the connection open; already-held channels don't count against the quota, and unsubscribing frees a slot.
  • Channels created by failed subscriptions (such as an invalid auth signature) are removed when empty, preventing a slow leak.
  • No config migration is required — a published config missing the new key falls back to the 1,000-channel default.

Sources

Related Articles