Skip to content

internal: migrate CancelRequest to context deadline - #413

Open
prattmic wants to merge 1 commit into
golang:masterfrom
prattmic:push-kkxtpxyxprpv
Open

prattmic wants to merge 1 commit into
golang:masterfrom
prattmic:push-kkxtpxyxprpv

Conversation

@prattmic

Copy link
Copy Markdown
Member

In upcoming Go 1.28, the deprecated Transport.CancelRequest has become no-op, causing TestAPICallRPCFailure to timeout because the in-flight request is never canceled. Set the deadline using context.WithTimeout instead, matching the current recommended way of canceling request.

@prattmic

Copy link
Copy Markdown
Member Author

cc @gajjarc

@prattmic

Copy link
Copy Markdown
Member Author

I tried to go out of my way to test that this works with Go 1.11, the oldest supported version according to go.mod, but it turns out this module already doesn't build with 1.11. 🙃

In upcoming Go 1.28, the deprecated Transport.CancelRequest has become
no-op, causing TestAPICallRPCFailure to timeout because the in-flight
request is never canceled. Set the deadline using context.WithTimeout
instead, matching the current recommended way of canceling request.

Note that this also means that cancelling the context passed to post
will cancel the HTTP request, which it previously would not.

Creating a context with timeout has a few more allocations than creating
a timer + closure, so bump the limits on TestAPICallAllocations. Part of
this is due to additional allocations from extending the parent context
with an additional timeout.

For what it's worth, I'm not convinced that absolute allocation count is
the best metric here, given how many dependencies Call has (net/http,
protobuf, etc). The v2 version of this test is not failing, but it's at
exactly 86, so bump it so the next tiny change doesn't break it.
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