-
Notifications
You must be signed in to change notification settings - Fork 5.5k
listener: fix sharedSocket #17090
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
listener: fix sharedSocket #17090
Changes from 6 commits
759a38b
f142345
f55e317
a12492f
06d434b
14b244a
34e6c6f
df2d945
60cdee7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,11 +57,16 @@ class ListenSocketFactoryImpl : public Network::ListenSocketFactory, | |
| * @return the socket shared by worker threads; otherwise return null. | ||
| */ | ||
| Network::SocketOptRef sharedSocket() const override { | ||
| // If a tcp listener socket doesn't bind to port, there is no listen socket so there is no | ||
| // shared socket. | ||
| if (socketType() == Network::Socket::Type::Stream && !bind_to_port_) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this apply only to Stream sockets or should it also apply to other socket types?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good question!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regardless the semantic of bind_to_port in UDP world, the implementation of UDP on bind_to_port = false is that a socket is created so sharedSocket() must returns it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the answer to the original question: However, if udp listener turns to not create socket on bind_to_port==false, this sharedSocket() need to align with that change.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to have the behaviors in sync. bind_to_port == false doesn't make much sense to me for UDP, I wonder if it should be disallowed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree this PR is somewhat changing the contract of sharedSocket(). Essentially we have two approaches, one is to provide a dedicate socket impl for listener doesn't bind to port. That specialized socket can be returned by sharedSocket(). The other approach in this PR is not to allow sharedSocket() from the beginning. Close is not an issue as per implementation: no underlying BSD socket is created so we are not leaking fd.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I mentioned elsewhere, I'm currently working on simplifying all of this code, so I would prefer to not make major changes here which I'm going to undo anyway. Per my above comment, why can't we just check if io_handle_ is null in various places?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I feel this PR has two part: sharedSocket() and the the ListenerSocketImpl. Your changes will delete sharedSocket(). However, the latter ListenerSocketImpl is needed. The reason is that your commits seems create number of concurrency listen socket regardless it's bind_to_port, for simplicity. I don't know how is that listenersocket closed correctly... I could be wrong though.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry I can't parse this. We can review my other change when I post it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, i had the wrong impression of udp listen socket always need a not-nullptr io_handle even when bind_to_port is false. I discovered this "fact" and I now incline to believe the fact is b/c a test case is improperly using listener socket. |
||
| return absl::nullopt; | ||
| } | ||
| if (!reuse_port_) { | ||
| ASSERT(socket_ != nullptr); | ||
| return *socket_; | ||
| } | ||
| // If reuse_port is true, always return null, even socket_ is created for reserving | ||
| // If reuse_port is true, always return nullopt, even socket_ is created for reserving | ||
| // port number. | ||
| return absl::nullopt; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.