-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Adds error code for context deadline exceeded #2008
Conversation
Hi, thanks for proposing this. I think this might need a deeper refactor though. As for your questions:
I think it's mostly arbitrary, with some distance between each to give us room to expand if needed.
Apparently not 😞 But like I mentioned above, we should probably wrap it in our own internal errors and use those in the switch, so that we don't have to deal with it directly. As you know from your other PR, I'll have to discuss this with the other team members, and we surely won't merge this for this upcoming release, so we have some time to figure out the details. Thanks again! |
I understand. If that's the case, how do we feel about extending this PR a little bit to also create a My gut says we can handle that with a small change here but let me know if that doesn't make sense. |
I think that would be OK, and that location seems right to me. But you should probably wait for feedback from @na-- or @mstoykov sometime next week before starting, they might have a better idea. BTW, I was wrong about error codes being arbitrary 🤦♂️ There's actually some logic to the grouping I forgot about: https://k6.io/docs/javascript-api/error-codes/ Though I'm not sure where to place this request timeout error, since it's not an HTTP or TCP error, just a context timeout... Maybe under General, so |
Yeah, that seems about right. You should also be able to directly use the |
@@ -243,6 +243,9 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { | |||
reqWithTracer := req.WithContext(httptrace.WithClientTrace(ctx, tracer.Trace())) | |||
resp, err := t.state.Transport.RoundTrip(reqWithTracer) | |||
|
|||
if typErr, ok := err.(net.Error); ok && typErr.Timeout() { | |||
err = NewK6Error(requestTimeoutErrorCode, requestTimeoutErrorCodeMsg, err) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up having to put this in transport
instead of request.go
. Since transport
actually takes care of reporting the error here we need to wrap it goes any further - I tested this with a built CLI to confirm that the error code does propagate all the way to the JS response object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm we already have something like this in here, but it seems only for dial timeouts: https://github.com/k6io/k6/blob/baa5a8af1591ef3c8aa5d5cb1540bceb4a550b6e/lib/netext/httpext/error_codes.go#L143-L146
And it seems likely that your current fix masks that branch, i.e. we'd no longer be able to distinguish between a dial timeout and a timeout after the TCP connection was established. If you move your check in this if
body, it will probably also work, without masking dial
timeout detection, and while keeping the error detection code in the same place: https://github.com/k6io/k6/blob/baa5a8af1591ef3c8aa5d5cb1540bceb4a550b6e/lib/netext/httpext/error_codes.go#L132
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be misunderstanding here but I think the err
type returned from RoundTrip
is a context.deadlineExceededError
. This means that it'll never end up making it into errorCodeForNetOpError
here. This is also shown by the fact that context deadline exceeded
errors return a code of 1000 which is not returned anywhere from errorCodeForNetOpError
.
I think that given that these errors will be completely separate times, it should prevent us from masking the dial
related errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error you create here and then get set in the struct below is the one that then goes through the error_code matching code and net.OpError
(the one that is matched in there) does implement net.Error
so it will definitely mask it ;).
On the other hand, I am not really certain it is needed, the original code (written by me) was just me trying to match as many errors as we have seen "somehow" which was over a year ago and so the current niceties in the errors
package weren't there.
I probably should've had just one timeout error as it is here and had it do everything.
I am not even certain we have had dial timeout error
at any point in time or have I just by reading the net
code found that this will match something "hopefully" and added it, I certainly tried this for a lot of errors that turned out later weren't matched correctly, because I didn't get the exact wrapping correct and there wasn't errors.As :(.
So I am fine with just dropping the dial timeout error code (and code) and having the rest of the change as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - if we think that creating a generic "timeout" error code is more useful then I've removed the dial conditional of the netOp error branch. Let me know if this isn't what you had in mind.
Codecov Report
@@ Coverage Diff @@
## master #2008 +/- ##
==========================================
+ Coverage 71.72% 71.73% +0.01%
==========================================
Files 179 179
Lines 14085 14086 +1
==========================================
+ Hits 10102 10105 +3
+ Misses 3347 3345 -2
Partials 636 636
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
92e1c88
to
1675211
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the PR 🎉
After looking at some more data it seems that dial timeout does happen quite often, and it's probably going to be better if we keep it so we can differentiate between them. But also it will be nice to have a test so I am for just merging this PR as is and I will try to add it back in #2025 and write a test for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah, the current PR is better than before, Request timeout
is a much better error message than context deadline exceeded
.
That said, it would be even better if we could differentiate between dial timeouts (i.e. k6 times out before it even could establish a network connection to the remote host) and between timeouts (the connection was established, but the request didn't finish before the specified timeout duration).
So I am fine with merging this PR as it is and trying to fix that in #2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for this! Let's just squash it when we merge/rebase.
One tiny nitpick is that I would make "Request timeout" lowercase to match the other errors, but we can fix that later.
This was dropped as part of #2008 but it will be better if we differentiate between different timeouts
This was dropped as part of #2008 but it will be better if we differentiate between different timeouts
This was dropped as part of #2008 but it will be better if we differentiate between different timeouts Also add test for the `request timeout` error code in `httpext`
This was dropped as part of #2008 but it will be better if we differentiate between different timeouts Also add test for the `request timeout` error code in `httpext`
This was dropped as part of #2008 but it will be better if we differentiate between different timeouts Also add test for the `request timeout` error code in `httpext`
This was dropped as part of #2008 but it will be better if we differentiate between different timeouts Also add test for the `request timeout` error code in `httpext`
I came across this issue and wanted to take a stab adding a code for context deadline exceeded errors since http timeouts are near and dear to my heart. I know the task is tagged as
refactor
so I'm not sure if a larger overhaul is due, but I figure this is a small change to cover a frequent error code and might be worth getting in sooner.A few notes / questions about this: