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
Fix: [Network] Error handling on Windows broken #9116
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rubidium42
added
the
backport requested
This PR should be backport to current release (RC / stable)
label
Apr 27, 2021
TrueBrain
reviewed
Apr 27, 2021
rubidium42
force-pushed
the
winsock-uses-no-errno
branch
2 times, most recently
from
April 27, 2021 10:20
5e4f1c1
to
51ba093
Compare
TrueBrain
reviewed
Apr 27, 2021
PeterN
reviewed
Apr 27, 2021
…numbers that need to be looked up
…twork errors They are likely not working as expected on Windows, so prevent their usage. Winsock does not set errno and strerror does not return anything useful for Winsock error numbers.
rubidium42
force-pushed
the
winsock-uses-no-errno
branch
from
April 27, 2021 10:58
51ba093
to
52a6fb9
Compare
TrueBrain
approved these changes
Apr 27, 2021
LordAro
reviewed
Apr 27, 2021
LordAro
added
backported
This PR is backported to a current release (RC / stable)
and removed
backport requested
This PR should be backport to current release (RC / stable)
labels
May 3, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
Testing #9112 on Windows I found out it did not work. Looking at the specs I found out that errno is not useful for errors from Winsock; that's where GET_LAST_ERROR() was supposed to be used. However, strerror is not useful for errors from Winsock either and that has no abstraction, so most error messages on Windows from the network would be useless.
Description
Use GET_LAST_ERROR(), although renamed to NetworkGetLastError() to make it clearer it is only to be used for network errors, where errno was used in the network code.
Introduce NetworkGetLastErrorString which is strerror(NetworkGetLastError()) for everything but Windows; note that errno on OS/2 is also not used for socket errors, so also for OS/2 GET_LAST_ERROR() should have been used.
For Windows introduce NetworkGetLastErrorString that returns an error string using Windows' FormatMessage.
To prevent issues in the future, safeguards were added to not use strerror or errno in the networking code. "In the networking code" is everything that includes network/core/os_abstraction.h. That should generally be safe as, in theory, nothing outside the network could should touch that (with proper encapsulation ofcourse). However, it was leaking out through some header files, e.g. fios.h so some small changes were made to prevent leaking os_abstraction.h.
Limitations
Cannot use strerror/errno anymore when including os_abstraction.h (and safeguards.h), though if you need to there is probably some issue with encapsulation and the place that (indirectly) includes that knows way too much of the internal state of the network code.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.