Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shared client: Fix global timeout not being respected #11

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

gandro
Copy link
Member

@gandro gandro commented Apr 16, 2024

This fixes a bug where the shared client did not respect c.Client.Timeout, resulting in DNS requests timing out too soon.

A per Go docs, Client.Timeout is supposed to also apply to the write timeout. This is implemented in the regular client by using Client.getTimeoutForRequest to determine the actual timeout. This commit adapts the shared client code to do the same.

Ref: cilium/cilium#31999

This fixes a bug where the shared client did not respect
`c.Client.Timeout`, resulting in DNS requests timing out too soon.

A per Go docs, `Client.Timeout` is supposed to also apply to the write
timeout. This is implemented in the regular client by using
`Client.getTimeoutForRequest` to determine the actual timeout. This
commit adapts the shared client code to do the same.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
@gandro
Copy link
Member Author

gandro commented Apr 16, 2024

Not sure who owns this repo, so I've just added the few people who have contributed in the past

@marseel
Copy link

marseel commented Apr 16, 2024

@gandro
Copy link
Member Author

gandro commented Apr 16, 2024

Shouldn't that be something like this? https://github.com/cilium/cilium/blob/94f6553f5b79383b561e8630bdf40bd824769ede/vendor/github.com/cilium/dns/client.go#L250-L251

Not sure what you are suggesting. Using context.WithDeadline instead of WithTimeout? I don't think it makes a difference? Internally, they are identical.

@marseel
Copy link

marseel commented Apr 16, 2024

Ah, I was referring to the fact that we are adding two timeouts there - one for write and the other for read, so in theory we should do the same here I think, no?

Copy link

@marseel marseel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, nvm. This only applies to writing requests so it's fine.

@gandro
Copy link
Member Author

gandro commented Apr 16, 2024

Ah, I was referring to the fact that we are adding two timeouts there - one for write and the other for read, so in theory we should do the same here I think, no?

I'm honestly not sure how to implement the read timeout with the shared client. The logic is very convoluted.

The way I understand the code, the timeout created here:

timeout := c.getTimeoutForRequest(c.Client.writeTimeout())

Is passed via req.ctx to SendContext here:

err := client.SendContext(req.ctx, req.msg, conn, start)

Which then actually splits the passed in context into write and read timeouts. But I guess given the way it's implemented, if the write timeout is lower than the read timeout, then it will use our timeout created here as the read timeout too.

@gandro
Copy link
Member Author

gandro commented Apr 16, 2024

I did do some local testing and at least with this patch, the library now does respect the 10 second timeout Cilium configures, rather than falling back on the default dnsTimeout of two seconds which it did before. There might still be corner cases where the timeouts are messed up because of all the sharing, but since this already is an improvement over the status quo I'll merge as is.

@gandro gandro merged commit d47d0dd into master Apr 16, 2024
4 checks passed
@marseel
Copy link

marseel commented Apr 16, 2024

There might still be corner cases where the timeouts are messed up because of all the sharing, but since this already is an improvement over the status quo I'll merge as is.

yup, makes sense, that is my understanding as well.

gandro added a commit to gandro/cilium that referenced this pull request Apr 16, 2024
This pulls in cilium/dns#11 which fixes a bug where the `SharedClient`
logic did not respect the `c.Client.Timeout` field.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
github-merge-queue bot pushed a commit to cilium/cilium that referenced this pull request Apr 22, 2024
This pulls in cilium/dns#11 which fixes a bug where the `SharedClient`
logic did not respect the `c.Client.Timeout` field.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
gandro added a commit to cilium/cilium that referenced this pull request Apr 29, 2024
[ upstream commit c76677d ]

This pulls in cilium/dns#11 which fixes a bug where the `SharedClient`
logic did not respect the `c.Client.Timeout` field.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
gandro added a commit to cilium/cilium that referenced this pull request Apr 30, 2024
[ upstream commit c76677d ]

This pulls in cilium/dns#11 which fixes a bug where the `SharedClient`
logic did not respect the `c.Client.Timeout` field.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
gandro added a commit to cilium/cilium that referenced this pull request Apr 30, 2024
[ upstream commit c76677d ]

This pulls in cilium/dns#11 which fixes a bug where the `SharedClient`
logic did not respect the `c.Client.Timeout` field.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
gandro added a commit to cilium/cilium that referenced this pull request May 2, 2024
[ upstream commit c76677d ]

This pulls in cilium/dns#11 which fixes a bug where the `SharedClient`
logic did not respect the `c.Client.Timeout` field.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
gandro added a commit to cilium/cilium that referenced this pull request May 2, 2024
[ upstream commit c76677d ]

This pulls in cilium/dns#11 which fixes a bug where the `SharedClient`
logic did not respect the `c.Client.Timeout` field.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
gandro added a commit to cilium/cilium that referenced this pull request May 2, 2024
[ upstream commit c76677d ]

This pulls in cilium/dns#11 which fixes a bug where the `SharedClient`
logic did not respect the `c.Client.Timeout` field.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants