verifier_tools/verify: Factor shared HTTP client and add checkpoint t… - #32
Merged
Merged
Conversation
…imeouts/context Previously, `getSignedCheckpoint` in `internal/checkpoint/checkpoint.go` called `http.Get` directly, using `http.DefaultClient` (`Timeout: 0`) without caller `context.Context` propagation. If a remote server stalled or dropped packets while fetching `checkpoint` or `checkpoint.txt`, the verifier could block indefinitely. 1. Factor the tuned `http.Transport` configuration (`DialContext` with `10s` timeout, `ForceAttemptHTTP2: true`, `TLSHandshakeTimeout: 10s`, and `ResponseHeaderTimeout: 30s`) into `internal/httpclient.New(timeout)` and share it across `internal/tiles` (`5m` total timeout) and `internal/checkpoint` (`30s` total timeout). 2. Add `getSignedCheckpointContext` and `FromURLWithPathContext` in `internal/checkpoint` using `http.NewRequestWithContext` and `%w` error wrapping to preserve timeout and cancellation error chains. 3. Wire `signal.NotifyContext` (`SIGINT`/`SIGTERM`) in `cmd/verifier/verifier.go` across both `--fetch_entries` and `--payload_path` verification paths so signal cancellation propagates to all checkpoint fetches. Test: - `cd verifier_tools/verify && gofmt -l . && go test -race -v ./...` - Added `TestNew` in `internal/httpclient/httpclient_test.go` and `TestHTTPClientTimeoutAndContextCancellation` in `internal/checkpoint/checkpoint_test.go`. Change-Id: Ibcadd345cf22a38083b9f7fb86c5379c8681fb59
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.
…imeouts/context
Previously,
getSignedCheckpointininternal/checkpoint/checkpoint.gocalledhttp.Getdirectly, usinghttp.DefaultClient(Timeout: 0) without callercontext.Contextpropagation. If a remote server stalled or dropped packets while fetchingcheckpointorcheckpoint.txt, the verifier could block indefinitely.http.Transportconfiguration (DialContextwith10stimeout,ForceAttemptHTTP2: true,TLSHandshakeTimeout: 10s, andResponseHeaderTimeout: 30s) intointernal/httpclient.New(timeout)and share it acrossinternal/tiles(5mtotal timeout) andinternal/checkpoint(30stotal timeout).getSignedCheckpointContextandFromURLWithPathContextininternal/checkpointusinghttp.NewRequestWithContextand%werror wrapping to preserve timeout and cancellation error chains.signal.NotifyContext(SIGINT/SIGTERM) incmd/verifier/verifier.goacross both--fetch_entriesand--payload_pathverification paths so signal cancellation propagates to all checkpoint fetches.Test:
cd verifier_tools/verify && gofmt -l . && go test -race -v ./...TestNewininternal/httpclient/httpclient_test.goandTestHTTPClientTimeoutAndContextCancellationininternal/checkpoint/checkpoint_test.go.Change-Id: Ibcadd345cf22a38083b9f7fb86c5379c8681fb59