Skip to content

listener: add SO_REUSEPORT support for TcpListenSocket by option and UdpListenSocket forcibly - #8884

Merged
mattklein123 merged 21 commits into
envoyproxy:masterfrom
l8huang:reuse-port
Dec 4, 2019
Merged

mattklein123 merged 21 commits into
envoyproxy:masterfrom
l8huang:reuse-port

Conversation

@l8huang

@l8huang l8huang commented Nov 5, 2019 •

Copy link
Copy Markdown
Contributor

This change makes TCP and UDP listeners supporting SO_REUSEPORT. For TCP, it can be switched on/off by option 'reuse_port' added to envoy.api.v2.Listener; For UDP, it's always on, the value of 'reuse_port' is ignored.

Signed-off-by: lhuang8 [email protected]

Risk Level: Medium
Testing: Update UTs and integration tests, new UT cases added
Docs Changes:
Release Notes:
Fixes #8794

Make TCP listeners supporting SO_REUSEPORT, then each worker thread will create
and listen on socket using same address and port.

Signed-off-by: lhuang8 <[email protected]>
@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/.

🐱

Caused by: #8884 was opened by l8huang.

see: more, trace.

@mattklein123

Copy link
Copy Markdown
Member

@l8huang I think @danzh2010 is already working on this so this might conflict with her work. I will let her chime in.

@danzh2010 danzh2010 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@l8huang, ListenerConfig change is conflicting with what I am doing now. And the SO_REUSEPORT part is not. I still need to address the use case of hot restart in my PR before sending it out for review. But I think you can continue work on protobuf and SO_REUSEPORT change in this PR.

Comment thread include/envoy/network/listener.h Resolved
Signed-off-by: lhuang8 <[email protected]>
Signed-off-by: lhuang8 <[email protected]>
@danzh2010

Copy link
Copy Markdown
Contributor

This PR needs to sync with #8976. After that, do you mind to change this PR to add SO_REUSEPORT support for TcpListenSocket by option and UdpListenSocket all the time?

@l8huang

l8huang commented Nov 14, 2019

Copy link
Copy Markdown
Contributor Author

@danzh2010 sure, I will merge your change and do so ;)

lhuang8 added 2 commits November 17, 2019 04:18
Signed-off-by: lhuang8 <[email protected]>
@l8huang l8huang changed the title listener: allow REUSEPORT for TCP listener sockets [draft] listener: add SO_REUSEPORT support for TcpListenSocket by option and UdpListenSocket forcibly Nov 17, 2019
Signed-off-by: lhuang8 <[email protected]>
@mattklein123

Copy link
Copy Markdown
Member

Can you merge master and then we can take a look? Excited to see this land to get SO_REUSEPORT for UDP listeners!

/wait

@l8huang

l8huang commented Nov 18, 2019

Copy link
Copy Markdown
Contributor Author

@danzh2010 @mattklein123 merged master, could you please take a look?

@danzh2010 danzh2010 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this!

Comment thread include/envoy/network/listener.h Resolved
Comment thread source/server/listener_manager_impl.cc Resolved
Comment thread test/server/connection_handler_test.cc Resolved
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved

@l8huang l8huang left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for review :)

Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_manager_impl.cc Resolved
Comment thread include/envoy/network/listener.h Resolved
Comment thread source/server/listener_impl.cc Resolved
Signed-off-by: lhuang8 <[email protected]>
lhuang8 added 3 commits November 26, 2019 14:27
Signed-off-by: lhuang8 <[email protected]>
Signed-off-by: lhuang8 <[email protected]>
Signed-off-by: lhuang8 <[email protected]>
@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/.

🐱

Caused by: #8884 was synchronize by l8huang.

see: more, trace.

@mattklein123 mattklein123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, awesome work. Looks great modulo some small comments and sorting out @danzh2010 comment on the additional factories.

/wait

Comment thread docs/root/intro/version_history.rst Resolved
Comment thread api/envoy/api/v3alpha/lds.proto Resolved
Comment thread source/server/listener_impl.cc Resolved
Signed-off-by: lhuang8 <[email protected]>
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.h Resolved
Comment thread source/server/listener_manager_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved

@l8huang l8huang left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for comments

Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.cc Resolved
Comment thread source/server/listener_impl.h Resolved
Comment thread source/server/listener_manager_impl.cc Resolved
Signed-off-by: lhuang8 <[email protected]>
// If a listener's port is set to 0, socket_ should be created for reserving a port
// number, it is handed over to the first worker thread came here.
// There are several reasons for doing this:
// - for UDP, once a socket being bound, it begins to receive packets, it can't be

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As an aside, I'm not sure how much this really matters. There is going to be a delay between creating the socket on the main thread and when the first worker actually steals it (the delay may be very large due to xDS init, etc.). In general this should be covered by downstream health check, etc. This is related to an offline conversation I had with @danzh2010 about UDP and hot restart. I think it probably will never work correctly with stateless protocols like QUIC. I will open an issue to figure out how to deal with that.

mattklein123
mattklein123 previously approved these changes Dec 2, 2019

@mattklein123 mattklein123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this works for me. I don't have a strong opinion on the final back and forth between you and @danzh2010. @danzh2010 LMK when you are satisfied. Great work!

@repokitteh-read-only repokitteh-read-only Bot added waiting and removed api labels Dec 2, 2019
> The only need of reuse_port here is to add SO_REUSEPORT option. You can
> just embed
> (socket_type_ == Network::Address::SocketType::Datagram) ? true : config.reuse_port()
> in the if condition.
> You can also change ListenerManagerImpl::createListenSocketFactory() to take reuse_port
> as parameter, and its caller ListenerManagerImpl::addOrUpdateListener() should also have
> access to config. So ListenerImpl doesn't need reusePort() interface.

Signed-off-by: lhuang8 <[email protected]>
Signed-off-by: lhuang8 <[email protected]>

@mattklein123 mattklein123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome, thanks!

@repokitteh-read-only repokitteh-read-only Bot removed the api label Dec 4, 2019
@mattklein123

Copy link
Copy Markdown
Member

/azp run envoy-linux

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mattklein123
mattklein123 merged commit 8534ac8 into envoyproxy:master Dec 4, 2019
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.

Allow REUSEPORT for listener sockets

4 participants