warmcat / libwebsockets

canonical libwebsockets.org networking library
https://libwebsockets.org
Other
4.75k stars 1.48k forks source link

lws_client_connect_via_info seems to fail silently when previous GET returned status=204 #2844

Open wreuven opened 1 year ago

wreuven commented 1 year ago

lws_client_connect_via_info returns non-null but no corresponding GET appears in wireshark

This is called right after LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP since neither LWS_CALLBACK_CLIENT_CONNECTION_ERROR nor LWS_CALLBACK_COMPLETED_CLIENT_HTTP is called after the status=204.

When I don't do another GET, I do eventually get a LWS_CALLBACK_CLIENT_CONNECTION_ERROR read() error like 15 seconds after the 204, presumably when the socket is closed by server, but there is nothing to read on a 204 and I should be able to do a GET right after getting the 204 response.

using v4.3-stable

wreuven commented 1 year ago

Trying to reproduce with minimal sample code.

Server alternates between hello world and return 204 status

$ cat server.js
const http = require('http');

let isNoContent = false;

const server = http.createServer((req, res) => {
  if (isNoContent) {
    res.writeHead(204);
    res.end();
  } else {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Hello, World!');
  }
  isNoContent = !isNoContent; // toggle the response type
});

const port = process.env.PORT || 3000;
server.listen(port, () => {
  console.log(`Server running on port ${port}`);
});

As expected. When run without pipelining.

$ ./bin/lws-minimal-http-client-multi -l --port 3000 --no-tls |& grep read
[2023/03/05 11:28:43:7839] U: RECEIVE_CLIENT_HTTP_READ: conn 4: read 13
[2023/03/05 11:28:43:7840] U: RECEIVE_CLIENT_HTTP_READ: conn 2: read 13
[2023/03/05 11:28:43:7840] U: RECEIVE_CLIENT_HTTP_READ: conn 0: read 13
[2023/03/05 11:28:43:7845] U: RECEIVE_CLIENT_HTTP_READ: conn 6: read 13

But when run without pipelining, things go south after the first 204

$ ./bin/lws-minimal-http-client-multi -l --port 3000 --no-tls -p |& grep read
[2023/03/05 11:28:54:5160] U: RECEIVE_CLIENT_HTTP_READ: conn 0: read 13
[2023/03/05 11:28:59:5215] E: CLIENT_CONNECTION_ERROR: read failed