]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
multi: fix multi_wait() timeout handling
authorStefan Eissing <stefan@eissing.org>
Wed, 29 May 2024 15:13:34 +0000 (17:13 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 30 May 2024 06:29:00 +0000 (08:29 +0200)
- determine the actual poll timeout *after* all sockets
  have been collected. Protocols and connection filters may
  install new timeouts during collection.
- add debug logging to test1533 where the mistake was noticed

Reported-by: Matt Jolly
Fixes #13782
Closes #13825

lib/multi.c
tests/libtest/Makefile.inc
tests/libtest/lib1553.c

index 2f9c0c70d75877cb5361a957e85dfd2c444c60e7..a3e784a8990bcae87c4dee10282b9811d6b49504 100644 (file)
@@ -1366,13 +1366,6 @@ static CURLMcode multi_wait(struct Curl_multi *multi,
   if(timeout_ms < 0)
     return CURLM_BAD_FUNCTION_ARGUMENT;
 
-  /* If the internally desired timeout is actually shorter than requested from
-     the outside, then use the shorter time! But only if the internal timer
-     is actually larger than -1! */
-  (void)multi_timeout(multi, &timeout_internal);
-  if((timeout_internal >= 0) && (timeout_internal < (long)timeout_ms))
-    timeout_ms = (int)timeout_internal;
-
   memset(ufds, 0, ufds_len * sizeof(struct pollfd));
   memset(&ps, 0, sizeof(ps));
 
@@ -1476,6 +1469,14 @@ static CURLMcode multi_wait(struct Curl_multi *multi,
 #endif
 #endif
 
+  /* We check the internal timeout *AFTER* we collected all sockets to
+   * poll. Collecting the sockets may install new timers by protocols
+   * and connection filters.
+   * Use the shorter one of the internal and the caller requested timeout. */
+  (void)multi_timeout(multi, &timeout_internal);
+  if((timeout_internal >= 0) && (timeout_internal < (long)timeout_ms))
+    timeout_ms = (int)timeout_internal;
+
 #if defined(ENABLE_WAKEUP) && defined(USE_WINSOCK)
   if(nfds || use_wakeup) {
 #else
index d5589eee9515c258b016c0262aa4ecf3ff37d3d6..371f26656269219aeb1bd1e321d69b880fb13972 100644 (file)
@@ -487,7 +487,7 @@ lib1551_SOURCES = lib1551.c $(SUPPORTFILES)
 lib1552_SOURCES = lib1552.c $(SUPPORTFILES) $(TESTUTIL)
 lib1552_LDADD = $(TESTUTIL_LIBS)
 
-lib1553_SOURCES = lib1553.c $(SUPPORTFILES) $(TESTUTIL)
+lib1553_SOURCES = lib1553.c $(SUPPORTFILES) $(TSTTRACE) $(TESTUTIL)
 lib1553_LDADD = $(TESTUTIL_LIBS)
 
 lib1554_SOURCES = lib1554.c $(SUPPORTFILES)
index 97053991a915c4ad1f1c4043485518354ec6aca9..998c0762aaf5319bcb460ddcfb497f11a03566ca 100644 (file)
@@ -24,6 +24,7 @@
 #include "test.h"
 
 #include "testutil.h"
+#include "testtrace.h"
 #include "warnless.h"
 #include "memdebug.h"
 
@@ -74,6 +75,12 @@ CURLcode test(char *URL)
   easy_setopt(curls, CURLOPT_XFERINFOFUNCTION, xferinfo);
   easy_setopt(curls, CURLOPT_NOPROGRESS, 1L);
 
+  libtest_debug_config.nohex = 1;
+  libtest_debug_config.tracetime = 1;
+  test_setopt(curls, CURLOPT_DEBUGDATA, &libtest_debug_config);
+  easy_setopt(curls, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
+  easy_setopt(curls, CURLOPT_VERBOSE, 1L);
+
   multi_add_handle(multi, curls);
 
   multi_perform(multi, &still_running);