diff --git a/lib/roles/ws/ops-ws.c b/lib/roles/ws/ops-ws.c index 85eb8de3a0..67092e338b 100644 --- a/lib/roles/ws/ops-ws.c +++ b/lib/roles/ws/ops-ws.c @@ -942,6 +942,7 @@ lws_is_ws_with_ext(struct lws *wsi) #endif } +#define SANITY_READS (10) static int rops_handle_POLLIN_ws(struct lws_context_per_thread *pt, struct lws *wsi, struct lws_pollfd *pollfd) @@ -949,7 +950,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, sanity = 10; + int n = 0, m, sanity = SANITY_READS, zero_len_reads = 0; #if defined(LWS_WITH_HTTP2) struct lws *wsi1; #endif @@ -1193,6 +1194,7 @@ rops_handle_POLLIN_ws(struct lws_context_per_thread *pt, struct lws *wsi, /* we closed wsi */ return LWS_HPI_RET_WSI_ALREADY_DIED; } + if (n == 0) zero_len_reads++; //lws_buflist_describe(&wsi->buflist, wsi, __func__); //lwsl_notice("%s: consuming %d / %d\n", __func__, n, ebuf.len); if (ebuf.len < 0 || @@ -1246,7 +1248,7 @@ rops_handle_POLLIN_ws(struct lws_context_per_thread *pt, struct lws *wsi, * Something has gone wrong, we are spinning... * let's bail on this connection */ - return LWS_HPI_RET_PLEASE_CLOSE_ME; + return zero_len_reads == SANITY_READS ? LWS_HPI_RET_PLEASE_CLOSE_ME : LWS_HPI_RET_HANDLED; } if (buffered && /* were draining, now nothing left */