From b46bb8504be413a5dfae24b325c3b134aeaf02ea Mon Sep 17 00:00:00 2001 From: Jessie Murray Date: Sat, 17 Jul 2021 13:16:15 -0700 Subject: [PATCH] Mark websocket http responses as keep_alive The keep_alive flag is needed on http_response for websocket connections. Without it, the server closes the connection as soon as a reply to the first frame is sent. --- src/websocket.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/websocket.c b/src/websocket.c index c8482f6..8aae00e 100644 --- a/src/websocket.c +++ b/src/websocket.c @@ -415,12 +415,14 @@ ws_reply(struct cmd *cmd, const char *p, size_t sz) { /* send WS frame */ r = http_response_init(cmd->w, 0, NULL); - if (cmd_is_subscribe(cmd)) { - r->keep_alive = 1; + if (r == NULL) { + free(frame); + slog(cmd->w->s, WEBDIS_ERROR, "Failed response allocation in ws_reply", 0); + return -1; } - if (r == NULL) - return -1; + /* mark as keep alive, otherwise we'll close the connection after the first reply */ + r->keep_alive = 1; r->out = frame; r->out_sz = frame_sz;