From c11311ff5a00f0db013059da907bdb688e21e518 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sun, 18 Jul 2021 11:16:45 +0100 Subject: [PATCH] ws: ext: close wsi rather than spin if unable to clear buflist If there's ssl pending and stuff in the buflist, it was observed we can spin if the buflist is not cleared due to wsi state. Add a sanity check for the number of times we will try to deal with that before dropping the conn. --- lib/roles/ws/ops-ws.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/roles/ws/ops-ws.c b/lib/roles/ws/ops-ws.c index 08299ca62..705c7acd1 100644 --- a/lib/roles/ws/ops-ws.c +++ b/lib/roles/ws/ops-ws.c @@ -943,7 +943,7 @@ rops_handle_POLLIN_ws(struct lws_context_per_thread *pt, struct lws *wsi, unsigned int pending = 0; struct lws_tokens ebuf; char buffered = 0; - int n = 0, m; + int n = 0, m, sanity = 10; #if defined(LWS_WITH_HTTP2) struct lws *wsi1; #endif @@ -1223,7 +1223,14 @@ drain: else pending = pending > wsi->a.context->pt_serv_buf_size ? wsi->a.context->pt_serv_buf_size : pending; - goto read; + if (--sanity) + goto read; + else + /* + * Something has gone wrong, we are spinning... + * let's bail on this connection + */ + return LWS_HPI_RET_PLEASE_CLOSE_ME; } if (buffered && /* were draining, now nothing left */