websocketd: fix random failures by blocking stdin reads

Example request that is dying:

NEW REQUEST! lightning_websocketd:main [1955685] <-- bad request from safari

   read 507
   write_all 1
-> websocket_to_lightningd
-> read_payload_header
   read 2
   read_all 1
   read -11      <--- This tried to read a part of the header, is this -EAGAIN?
   read_all 0         should we be blocking on these reads?
   *dies*

Fixes #5089

Changelog-Fixed: `experimental-websocket` intermittent read errors fixed
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin 2022-03-11 12:08:59 -08:00 committed by neil saitug
parent a2a6b8c3ff
commit f72a08c802

View file

@ -5,6 +5,7 @@
#include <ccan/base64/base64.h> #include <ccan/base64/base64.h>
#include <ccan/endian/endian.h> #include <ccan/endian/endian.h>
#include <ccan/err/err.h> #include <ccan/err/err.h>
#include <ccan/io/io.h>
#include <ccan/mem/mem.h> #include <ccan/mem/mem.h>
#include <ccan/read_write_all/read_write_all.h> #include <ccan/read_write_all/read_write_all.h>
#include <ccan/str/hex/hex.h> #include <ccan/str/hex/hex.h>
@ -326,6 +327,7 @@ int main(int argc, char *argv[])
errx(1, "Usage: %s", argv[0]); errx(1, "Usage: %s", argv[0]);
/* Do HTTP-style negotiation to get into websocket frames. */ /* Do HTTP-style negotiation to get into websocket frames. */
io_fd_block(STDIN_FILENO, true);
http_upgrade(STDIN_FILENO); http_upgrade(STDIN_FILENO);
pfds[0].fd = STDIN_FILENO; pfds[0].fd = STDIN_FILENO;