Skip to content

Web socket timeouts in 0.9.5 #1384

Closed
Closed
@splack

Description

@splack

1. What version of Caddy are you running (caddy -version)?

0.9.5

2. What are you trying to do?

Reverse proxy drone.io server web interface. I noticed that websockets were being closed and the web UI was not updating after a small time.

3. What is your entire Caddyfile?

Not working:

localhost:2015 {
  proxy /ws localhost:12345 {
    websocket
  }
}

localhost:12345 {
  websocket /bin/cat
}

Working:

localhost:2015 {
  timeouts {
    read 0
  }
  proxy /ws localhost:12345 {
    websocket
  }
}

localhost:12345 {
  websocket /bin/cat
}

Test html:

<html>
<head></head>
<body>
    <h1>WebSocket Echo Test</h1>
    <form>
        <p>
            Message: <input id="message" type="text" value="Hello, world!">
        </p>
    </form>
    <button id="sendButton" disabled="true" onclick="send();">Send Message</button>
    <button id="openButton" onclick="logPre.innerHTML='';">Open WebSocket</button>
    <pre id="log" />
    <script type="text/javascript">
        var state = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"]
        var sock = null;
        var wsuri = ("https:" === window.location.protocol ? "wss:" : "ws:") +
            "//" + window.location.host + "/ws/echo"
        var logPre = document.getElementById("log");
        var sendButton = document.getElementById("sendButton");
        var openButton = document.getElementById("openButton");
        function log(msg) {
            console.log(msg);
            var d = new Date().getTime() / 1000;
            logPre.innerHTML = logPre.innerHTML + d + "\t" + "sock is " +
                state[sock.readyState] + "\t" + msg + "\n";
        }
        function send() {
            var msg = document.getElementById("message").value;
            log("sending: " + msg);
            try {
                sock.send(msg);
            } catch (e) {
                log(e)
            }
        };
        window.onload = function() {
            console.log("onload");
            sock = new WebSocket(wsuri);
            send();
            sock.onopen = function() {
                sendButton.disabled = false;
                openButton.disabled = true;
                log("connected to " + wsuri);
                for (i = 1000; i <= 12000; i += 1000) {
                    window.setTimeout(send, i);
                }
            }
            sock.onclose = function(e) {
                sendButton.disabled = true;
                openButton.disabled = false;
                log("connection closed (" + e.code + ")");
            }
            sock.onmessage = function(e) {
                log("received: " + e.data);
            }
        };
    </script>
</body>
</html>

4. How did you run Caddy (give the full command and describe the execution environment)?

./caddy

5. What did you expect to see?

Open web sockets do not close after 10 seconds.

I think I've narrowed it down to the new default 10s read timeout. Should web sockets bypass the read timeout since the socket state is known?

6. What did you see instead (give full error messages and/or log)?

Web socket is being closed by caddy after 10 seconds.

7. How can someone who is starting from scratch reproduce this behavior as minimally as possible?

Use the files and html above.

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