-
Notifications
You must be signed in to change notification settings - Fork 53
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
reusePort = false now default; honored regardless of numThreads #50
Closed
timotheecour
wants to merge
1
commit into
dom96:master
from
timotheecour:pr_httpbeast_reusePort_multithread
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
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 don't like this. It completely ignores the user's wishes. If I ask for reuse port to be set to false then I want it to be set to false, not for httpbeast to assume it knows best and set it to true anyway.
reusePort
should be true by default and we shouldn't be doing this magic. You can just as easily do this "bind trick" without messing with what the user wants. Just check whether binding to the port works always, that will fix the problem you are fixing too.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.
this will guarantee it'll fail, I can't find any use case for that; the way I implemented it works with sane behavior with both reusePort:true|false (and I thought we had agreed on that earlier).
You can add an additional
enforceReusePortMultithread: bool
flag if you want for users that don't want the override, but it's of little utility as it's a guaranteed exception raised.What you're suggesting goes against the default set in stdlib, and users would have the wrong behavior by default (and would be subject to TOCTOU for numthreads=1)
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'd be ok with the following if needded:
replace
reusePort: bool
byreusePort: ReusePort = rpOff
withtype ReusePort = enum rpOff, rpOffStrict, rpOn
where default is same as in PR, and
rpOffStrict
causes reusePort=false and doesn't get reset by httpbeast.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.
httpbeast is it's own http library, I don't see why it needs to be consistent with stdlib.
With this PR you are giving
reusePort
a completely different meaning. It's no longer a simple setting for whetherSO_REUSE_PORT
should be set, we shouldn't be assigning different meanings to simple flags to handle some edge cases. If you want to avoid TOCTOU then you can surely just set this flag to false.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 tristate i suggested would make it clear and un-ambiguous; possibly with better name
type ReusePortPolicy
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.
But this is the right default for httpbeast because it relies on it for performance. This is only the wrong default because it allows other software to bind a socket on the same port, unfortunately that's the price you pay for performance and I would argue POSIX's design choices.
The dummy socket bind would happen only to detect that another instance of httpbeast (or another program) is running on that port.
Why do we need a user setting for this?
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.
neither this PR nor any of the alternatives I've suggested has any impact (positive or negative) on performance.
I may want to run multithread httpbeast on port 1234 and then another instance of the same program (or a different program) on the same port 1234, for eg for resilience or if I want N process times P threads instead of N*P threads. This should be up to user setting whether to fail-fast if a port is already taken.
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.
Yes, but you're doing that by ignoring the flag. Like I said, that's not acceptable.
Alright, fine so let's have another flag for this:
failOnExistingPort
or something.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 irony is that jester is ignoring this flag when not using httpbeast, so I don't see how neither the status quo nor your proposal is better. In any case, for the sake of moving on, I've opened an alternative PR, see #52 which uses
failOnExistingPort
, which should be followed by dom96/jester#281 (in jester) which forwards jester.reusePort=false to httpbeast.failOnExistingPort=true (IMO less clean than what I was doing and subject to TOCTOU when numThreads=1, unlike what I was doing in this PR)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 here's a version I'm happy with: #53, avoids TOCTOU, avoids ignoring a
reusePort
flag, sane default.