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

get rid of some panics #1526

Merged
merged 13 commits into from
Mar 30, 2023
Merged

get rid of some panics #1526

merged 13 commits into from
Mar 30, 2023

Conversation

mpldr
Copy link
Contributor

@mpldr mpldr commented Mar 20, 2023

Addresses #1522 and #1504. The latter is not fixed, but only referenced as the underlying double-close is not resolved.

Fixes: #1522

Remove an allocation in favour of deferring a call to release the
response.
Return an error instead of panicking if the user supplied a nonsensical
DialFunc.
If a compression level exceeding gzip's boundaries is provided, fasthttp
will panic. Instead it would be better to handle this error for them by
limiting it to the minimum or maximum value, depending on the direction
the user has exceeded the limits.

Clamp the value of gzip to always be between gzip.BestSpeed and
gzip.BestCompression.
Copy link
Collaborator

@erikdubbelboer erikdubbelboer left a comment

Choose a reason for hiding this comment

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

Can you fix the linting errors.

@mpldr
Copy link
Contributor Author

mpldr commented Mar 26, 2023 via email

@mpldr mpldr changed the title WIP: get rid of some panics get rid of some panics Mar 27, 2023
@mpldr mpldr requested review from erikdubbelboer and removed request for erikdubbelboer March 28, 2023 06:29
mpldr added 10 commits March 29, 2023 21:39
When a negative count is reached when unregistering a connection, a
panic is caused even though data-integrity is not at risk.

Replace the panic() with a simple clamp on the value to ensure the
value does not exceed it's expected lower bounds.

References: #1504
Since there is no way of handling or even logging non-critical errors in
stateless non-blocking writecalls, just drop them and hope the user
notices and tries again.
Instead of panicking for invalid behaviour, it's preferable to just turn
the function into a noop.
Since bufio already panics on negative reads, it is not necessary to do
so as well. If the length is zero and for some reason no error is
returned, readBodyIdentity and appendBodyFixedSize now errors in these
cases.

Link: https://github.com/golang/go/blob/851f6fd61425c810959c7ab51e6dc86f8a63c970/src/bufio/bufio.go#L246
When a negative count is reached when unregistering a reader, a panic is
thrown even though data-integrity is not at risk.

Replace the panic() with a simple clamp on the value to ensure the
value does not exceed it's expected lower bounds.
Panicking with "BUG: " obscures the error. As the segfault causes a
panic anyway, just let the chaos unfold.
Writing on a timed-out response is not endangering data integrity and
just fails.
@mpldr
Copy link
Contributor Author

mpldr commented Mar 29, 2023

/shrug Can't do anything about the tests taking too long

@erikdubbelboer erikdubbelboer merged commit d0f2727 into valyala:master Mar 30, 2023
@erikdubbelboer
Copy link
Collaborator

Thanks!

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.

Don't panic for non-critical errors
2 participants