Skip to content

Wait for the queue when close() is given an unbounded timeout - #19

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/close-unbounded-timeout
Oct 28, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/close-unbounded-timeout

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

  • TraceClient::close(timeoutSeconds) no longer converts an out-of-range double to long long, which is undefined behaviour. Before this change, close(INFINITY), close(DBL_MAX) and close(1e300) were observed to give up at once on x86-64/g++, so every queued report was dropped (see close() with an infinite or very large timeout drops every queued report #18).
  • A NaN or negative bound now waits for nothing. A bound past about three years (1e8 s, infinity included) would overflow the clock, so it waits on the condition with no deadline until the sending thread is done. Each request is still bounded by curl's 5 s timeout.
  • The close() doc comment and the README "close() drains" row now describe these bounds.

Test plan

  • make test (g++, C++11): 57 tests, 0 failed checks (55 before, plus 2 new tests, both registered in tests[])
  • Regression evidence: before the fix, closeWithABoundTooLongForTheClockSendsEverythingQueued failed (expected [5] got [0] for infinity, DBL_MAX and 1e300). After the fix it passes.
  • closeWithANegativeOrNanBoundWaitsForNothing checks that NaN, -1 and -INFINITY still return within 1 s while the server is held.
  • CI: linux matrix, linux-libcurl, linux-sanitizers, macos, windows

Skipped issue

Closes #18

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

close() turned timeoutSeconds * 1000 into a long long. For infinity,
NaN or a value past long long's range that conversion is undefined, and
on x86-64 close(INFINITY) gave up at once: the queue was cleared and
the curl in flight killed. A bound that fit in milliseconds could still
overflow the clock's nanoseconds (1e12 s).

NaN and negative bounds now wait for nothing, and a bound past about
three years waits on the condition with no deadline until the sending
thread is done. Each request is still bounded by curl's timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (head feature/close-unbounded-timeout, CI run 40643721166):

  • Scope: PASS. Three files changed: the fix in trace_client.hpp, two tests, and one README sentence describing the new bounds. No unrelated churn.
  • Tests-new: PASS. No new public API. The changed behaviour of close(double) is exercised by both new tests.
  • Tests-fix: PASS. Empirical: the tests were written and run before the fix and failed (closeWithABoundTooLongForTheClockSendsEverythingQueued: expected [5] got [0] for HUGE_VAL, DBL_MAX and 1e300). With the fix they pass: 57 tests, 0 failed checks.
  • Sibling structure: PASS. No new files. The tests follow the closeIsPromptAndIdempotent / closeReturnsWithinTheTimeoutWhenTheServerHangs pattern (StubServer, hold()/release(), secondsSince).
  • Sibling renames: PASS. Nothing renamed.
  • Docs: PASS. The close() doc comment and the README "close() drains" row both describe the NaN/negative and infinite bounds. The default 5 s bound and "Still bounded" are unchanged for the default call.
  • Issue resolution: PASS. close() with an infinite or very large timeout drops every queued report #18 names close()'s deadline computation, and that is the line changed.
  • CI: PASS. All 11 jobs are green: linux ×6, linux-libcurl, linux-sanitizers (thread; address,undefined), macos, windows.

Repo-specific:

  • Registered: PASS. Both new names appear twice in test/test_trace_client.cpp, and the count went from 55 to 57.
  • C++11: PASS. make test (default STD=c++11, -Werror) built clean, and the CI c++11 legs are green.
  • No new dependency: PASS. No #include or link flag added.
  • Never throws: PASS. The new wait(lock) sits inside close()'s existing try, and nothing new allocates.
  • Curl argv fixed: PASS. Spawn code, argv and config quoting are untouched.
  • Version triple: PASS. Unchanged.
  • Sanitizers: PASS. Both sanitizer jobs are green. The change touches the close/condition-variable wait, so the thread job is the meaningful one.

Notes:

  • trace_client.hpp:1050 — the 1e8 s cut-over is a judgment call. It keeps now() + bound well inside a signed 64-bit nanosecond count, including libstdc++'s conversion of the steady deadline to system_clock (~1.7e18 ns + 1e17 ns). Any bound above it is treated as "as long as it takes". An unbounded close() still ends: each request is limited by curl's max-time (or CURLOPT_TIMEOUT), and the queue holds at most 256 reports.
  • The Emscripten path is unaffected (shared_ is never set there, so close() returns before the changed code).

This review was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit aed004b into main Oct 28, 2026
11 checks passed
@dmccoystephenson
dmccoystephenson deleted the feature/close-unbounded-timeout branch October 28, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

close() with an infinite or very large timeout drops every queued report

1 participant