pgconn: preserve full error chain in normalizeTimeoutError#2556
Open
c-tonneslan wants to merge 2 commits into
Open
pgconn: preserve full error chain in normalizeTimeoutError#2556c-tonneslan wants to merge 2 commits into
c-tonneslan wants to merge 2 commits into
Conversation
When ConnectTimeout is set, connectPreferred creates a per-host timeout context derived from octx for each host. After the loop, ctx holds whatever context was used for the last attempt, which may have already expired. The fallback connection (for prefer-standby/prefer-primary) was using that stale ctx, so it would fail immediately with a deadline exceeded error even though the original context still had time left. Fix this by creating a fresh timeout context from octx for the fallback, same as we do for each host in the loop. Fixes jackc#2172
When a network timeout isn't caused by a context cancellation or deadline, normalizeTimeoutError was wrapping only the net.Error found via errors.As, discarding any outer error context (like DialError's address info). Wrap the original error instead so callers can still inspect the full chain. Fixes jackc#2383
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.
Fixes #2383.
When a network timeout isn't caused by a context cancellation or deadline exceeded,
normalizeTimeoutErrorwas wrapping only thenet.Errorfound viaerrors.As, discarding any outer context. For example, aDialErrorwrapping anet.OpErrorwrappingpoll.DeadlineExceededErrorwould have theDialError(including its address info) stripped off.The fix is to wrap
err(the full original error) rather thannetErr(the innernet.Errorextracted byerrors.As). This keeps the entire chain intact so callers can still inspect it. Thenet.Erroris still reachable viaerrors.Assince it's embedded in the chain.Added a test that verifies a
wrappedDialError{addr}wrapping atimeoutNetErroris still unwrappable after going throughnormalizeTimeoutError.