Repository navigation
proxy: propagate request cancellation to pending Fleet and command work - #496
Closed
ZayanKhan-12 wants to merge 1 commit into
Closed
ZayanKhan-12 wants to merge 1 commit into
ZayanKhan-12 wants to merge 1 commit into
Conversation
Per-request timeouts were derived from context.Background(), so a client disconnect left forwarded Fleet API I/O and vehicle lookup running. Derive the existing timeout from req.Context(), stop a dispatcher listener if Connect is canceled before Disconnect, and always Disconnect after a failed Connect.
5 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
tesla-http-proxyderived per-request timeouts fromcontext.Background(), so canceling the incoming HTTP request did not stop forwarded Fleet API I/O or vehicle lookup/session work. This PR derives the existing timeout fromreq.Context()on bothforwardRequestandhandleVehicleCommand, and stops a dispatcher listener ifConnectis canceled before the handler woulddefer Disconnect.Fixes #491
Related: #492 covers the REST-forwarding line only and deferred the vehicle-command path because of that dispatcher lifecycle. This PR includes that path.
Type of change
Please select all options that apply to this change:
Checklist:
Confirm you have completed the following steps:
Summary
Go's server request context is canceled when the client disconnects. The proxy must preserve that alongside
p.Timeout.What this PR does:
forwardRequestandhandleVehicleCommandusecontext.WithTimeout(req.Context(), p.Timeout).Dispatcher.Startcreates the terminate channel before listen, stops the listener ifctxis canceled before ready, and always signals ready on exit so Start cannot leak the goroutine.handleVehicleCommandcallsDisconnectafter a failedConnect.Test plan
go build ./... && go test ./... && go vet ./... && gofmt -l .go test -race ./pkg/proxy ./internal/dispatcherTestForwardRequestPropagatesRequestCancellationandTestHandleVehicleCommandPropagatesRequestCancellation(no sleeps)TestStartCanceledStopsListenerDisconnect