Websocket behind proxy - timeout after 10 seconds

Hello, I’m trying to use socket.io to do a really simple chat with websockets. It works when browsing directly to the site (eg :3000), but behind caddy’s proxy it doesn’t seem to keep the websocket alive (I’m not sure if that’s the right description for the issue).

http://i.imgur.com/mRMexk5.png - behind caddy’s proxy

http://i.imgur.com/JwLvVhn.png - direct access

I began reading the websocket directory page and I stumbled upon this:

Caddy will not make any effort to keep the backend process alive while a client is connected. It is the developer’s responsibility to ensure the program does not terminate until the client is ready to close the connection or would be ready for it to terminate.

Sadly, I don’t know what is meant by this – I tried to send an empty message via socket every 5 seconds but the connection doesn’t stay alive either, this way.

Relevant part of the config:

site.xyz {
  proxy / localhost:3000 {

Did you read the release notes? https://github.com/mholt/caddy/releases/tag/v0.9.5 - this will answer your question.

The current behavior is necessary to mitigate attacks but I’ve reluctantly disabled this security feature for future versions.

1 Like

Also, that is the proxy directive, not the websocket directive. :wink: The websocket preset for the proxy directive is a shorthand for a certain proxy configuration that handles websockets.

Hope that helps.

1 Like

Alright, adding timeouts 2h fixed it. Thanks! :grinning:

Cool. Sorry for the inconvenience.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.