Skip to content

Expose active WebSocket connection count in proxy #23

@romainvai

Description

@romainvai

Hello,

First of all, thank you for your work on this project — I've recently upgraded to your version of http-proxy and really appreciate the improvements.

I'm currently facing a challenge with managing WebSocket connections in my setup. I manually handle the upgrade using proxy.ws to track the number of active WebSocket clients. The idea is to start a stream API when at least one client is connected, and shut it down when there are none, as the stream is quite CPU-intensive.

To count clients, I rely on the "open" and "close" events from the proxy. However, this approach has proven unreliable in some edge cases:

  • When a connection is abruptly terminated (e.g., unplugging the Ethernet cable), the proxy "close" event is not triggered.
  • Restarting the stream API sometimes triggers the error event, but not consistently the close event.

As a workaround, I’ve tried forcibly calling socket.end() on all sockets when the proxy "error" event occurs, hoping it would trigger proxy "close" event — but I’m unsure if this is a robust solution.

Would it be possible for the proxy to expose the current number of active WebSocket connections directly? This would help avoid manual counting and reduce the risk of miscounting connections.

I’d be happy to share my code if needed, although I’m not sure it would add much value to the issue.

Thanks again for your work and support!

Best regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions