Skip to content

Fix HTTP probe timeout and cancel active probes on core stop - #214

Open
OneMiny wants to merge 2 commits into
2dust:mainfrom
OneMiny:fix/http-probe-timeout-and-cancellation
Open

OneMiny wants to merge 2 commits into
2dust:mainfrom
OneMiny:fix/http-probe-timeout-and-cancellation

Conversation

@OneMiny

@OneMiny OneMiny commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Problem

MeasureOutboundDelay can try the same URL twice. Each attempt had a separate 12-second HTTP client timeout, so a slow destination could keep a delay test running for up to about 24 seconds. The code also drained the body of an HTTP error before trying again, even after it had the error status.

MeasureDelay takes a snapshot of the running core. When the user stops the core during a connection check, the HTTP request can remain active after StopLoop returns.

Fix

  • Use one 12-second context for both attempts and pass it to the HTTP requests and Xray dial. Preserve the fastest successful attempt if the retry runs out of time.
  • Close rejected responses as soon as the status is known so a stalled error body cannot hold up the retry. Keep accepting HTTP 200 and 204.
  • Cancel the active probes under the lifecycle lock. Wait for the probe calls to release the instance before closing it. Each successful start gets a fresh context.
  • Register cleanup for the temporary core before starting it. The exported Go and Android interfaces stay the same.

This fix is based on #212 and uses its lifecycle mutex. PR #212

Scenario Before the fix · #212 After the fix
Endpoint waits eight seconds before HTTP 503 on each attempt Both requests ran. HTTP 503 returned after 16.01 s. Both requests started. One shared deadline ended the probe after 12.01 s with context.DeadlineExceeded.
Stop the core with three HTTP requests in flight StopLoop returned while the probes were still active. All three returned context.Canceled. A probe succeeded after restarting the same controller.
HTTP 503 headers arrive immediately, the error body stalls, and the next request can return 204 The retry completed after 12.01 s. The retry completed in about 0.01 s.
Local HTTP 200, 204 and 503 Both success codes passed and 503 returned an error. Same results.

Verification

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.

1 participant