Repository navigation
proxy: propagate vehicle request cancellation with startup cleanup - #535
maharshi-coding wants to merge 1 commit into
Conversation
Derive vehicle-command timeouts from the incoming request, establish cleanup ownership before Connect, and stop and join failed dispatcher startup without affecting another listener generation. Cover cancellation boundaries, exactly-once cleanup, startup concurrency, deadline bounds, and possible-success behavior after a synthetic send. Addresses the vehicle-command portion of teslamotors#491; REST forwarding and the separate StartSessions result-sender leak remain outside this change. Authored by Maharshi Barot, with AI assistance for investigation, implementation, testing, and review.
|
Ready for maintainer review — based on current Scope (re: #491). This addresses only the vehicle-command path ( Core change. Derive the per-command timeout from Validation (local, Go 1.27.x + golangci-lint v2.14.0):
An additional review pass (correctness / security / lifecycle), done with AI assistance, flagged no blocking issues. Implementation, design, and tests are my own; AI was used only as an assistant for investigation, validation, and review. Happy to split the dispatcher change into its own commit, or trim scope, if that's preferred. |
Description
When an HTTP client cancels a signed vehicle-command request, the proxy currently continues using a timeout derived from
context.Background(). Simply propagating the request context exposes a second problem:Dispatcher.Startcan return before the listener publishes its termination state, while the handler only defersDisconnectafter successfulConnect.This patch derives the vehicle-handler timeout from
req.Context(), registers cleanup before connection startup, and gives each dispatcher listener explicit ownership before launching it. Failed startup stops and joins that listener. Separate readiness/completion signals also make repeated starts and concurrent stops safe without an orphaned completion sender.Cancellation checks at setup boundaries prevent a successful setup return from advancing a canceled request, including the unsupported-protocol transition to REST fallback. Existing timeout bounds, vehicle error mappings, and cache-before-disconnect ordering remain intact.
Addresses the vehicle-command portion of #491. This deliberately leaves REST forwarding to #492 and the separate handshake result-sender leak to #494/#495/#515. It revisits the lifecycle concern identified in closed #496 without including its REST or documentation changes.
Cancellation does not recall a transmitted command or establish that it did not execute. The command retry/outcome policy is unchanged; a regression test verifies that cancellation after a synthetic send retains possible success, closes the receiver, and does not retry.
Regression evidence
Deterministic fake connectors and setup hooks cover canceled lookup/Connect/handshake stages, cleanup after failures, successful startup, parent deadlines and proxy timeouts, VIN serialization, independent VINs, unsupported fallback, concurrent startup waiters, and repeated/concurrent Stop.
Validation
Validated commit:
523adcc9707e37ac50dc80dbbd8e78fd56b0b040(based6239bf377b8a5859e8f5c9d64409df2a057934a).Local macOS arm64, CI-pinned Go 1.27.2 and golangci-lint v2.14.0:
go test ./...go test -race ./...go vet ./...go build ./...go test -cover ./...go install ./cmd/...golangci-lint run -v --timeout 30sgit diff --checkThese are local results; upstream GitHub Actions are not claimed as passed.
Scope and limitations
The separately tracked #494 worker leak remains unchanged, so this PR does not claim global goroutine-leak freedom. Listener joining assumes connector
Receiveand message processing return promptly, as the SDK's channel-returning connectors do. Cancellation inside REST forwarding remains #492's scope.Author and AI assistance
Implementation and regression tests by Maharshi Barot (@maharshi-coding), with AI assistance for investigation, implementation, testing, and review.
Type of change
Checklist