From 6ae977dffb4e32c05e37ff478543c788d956a8a1 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Thu, 25 Jun 2009 14:18:56 +0000 Subject: [PATCH] sbuf.c: Fix connection hang if sbuf_loopcnt is set. If query or result length nearby of multiple of (pktlen*sbuf_loopcnt) [10k by default], it could stay waiting for more data which will not appear. Fix it by resyncing and final processing before exiting loop. --- src/sbuf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/sbuf.c b/src/sbuf.c index 3213be0..fc5acaf 100644 --- a/src/sbuf.c +++ b/src/sbuf.c @@ -609,16 +609,22 @@ static void sbuf_main_loop(SBuf *sbuf, bool skip_recv) goto skip_recv; try_more: + /* make room in buffer */ + sbuf_try_resync(sbuf, false); + /* avoid spending too much time on single socket */ if (cf_sbuf_loopcnt > 0 && loopcnt >= cf_sbuf_loopcnt) { log_debug("loopcnt full"); + /* + * sbuf_process_pending() avoids some data if buffer is full, + * but as we exit processing loop here, we need to retry + * after resync to process all data. (result is ignored) + */ + ok = sbuf_process_pending(sbuf); return; } loopcnt++; - /* make room in buffer */ - sbuf_try_resync(sbuf, false); - /* * here used to be if (free > SBUF_SMALL_PKT) check * but with skip_recv switch its should not be needed anymore. -- 2.40.0