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

[bugfix] Overwrite API client closed errors with 499 - Client Closed Request #1857

Merged
merged 3 commits into from
Jun 2, 2023

Conversation

tsmethurst
Copy link
Contributor

Description

If this is a code change, please include a summary of what you've coded, and link to the issue(s) it closes/implements.

If this is a documentation change, please briefly describe what you've changed and why.

This pull request updates error logging in aputil to check if the error came about because the requester hung up the request before it could be completed. If so, whatever errWithCode was given is replaced with a less alarming error, that indicates that the client already closed the request before we could process it.

Not a standard error code, but then again it doesn't really matter because the client isn't going to see it anyway...

This should make it easier to debug GtS, since the logs won't show so many superfluous error messages.

Checklist

Please put an x inside each checkbox to indicate that you've read and followed it: [ ] -> [x]

If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).

  • I/we have read the GoToSocial contribution guidelines.
  • I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
  • I/we have performed a self-review of added code.
  • I/we have written code that is legible and maintainable by others.
  • I/we have commented the added code, particularly in hard-to-understand areas.
  • I/we have made any necessary changes to documentation.
  • I/we have added tests that cover new code.
  • I/we have run tests and they pass locally with the changes.
  • I/we have run go fmt ./... and golangci-lint run.

@@ -45,6 +48,10 @@ type withCode struct {
code int
}

func (e withCode) Original() error {
Copy link
Member

Choose a reason for hiding this comment

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

It would probably be here to instead implement this as Unwrap() error because then it will fit the errors.Unwrap() and errors.Is() function interface requirements :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I hope i did it right anyways 🤔

@@ -23,13 +23,21 @@ import (
"strings"
)

const (
StatusClientClosedRequest = 499
Copy link
Member

Choose a reason for hiding this comment

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

I'd maybe add a note here explaining these are only here because net/http doesn't contain them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

clientClosed = ctxErr != nil && (errors.Is(ctxErr, context.Canceled) || errors.Is(ctxErr, context.DeadlineExceeded))
)

if clientClosed {
Copy link
Member

Choose a reason for hiding this comment

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

I think you could probably just do if err := c.Request.Context().Err(); err != nil { here, not needing the above. Any returned context error here will be the base context that was originally set on the request and will only ever be one of deadline exceeded / canceled. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! Thanks :) Fixed!

@tsmethurst tsmethurst merged commit 2358cf4 into main Jun 2, 2023
@tsmethurst tsmethurst deleted the catch_client_closed_errors branch June 2, 2023 13:19
tsmethurst added a commit that referenced this pull request Jun 14, 2023
… Request` (#1857)

* [bugfix] Overwrite client closed errors with 499

* bleep bloop

* review changes
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.

None yet

2 participants