Skip to content

net: add set_listen_backlog() to update backlog on a live server socket#3312

Open
ScyllaPiotr wants to merge 1 commit into
scylladb:masterfrom
ScyllaPiotr:fix-ent-5614-seastar
Open

net: add set_listen_backlog() to update backlog on a live server socket#3312
ScyllaPiotr wants to merge 1 commit into
scylladb:masterfrom
ScyllaPiotr:fix-ent-5614-seastar

Conversation

@ScyllaPiotr

@ScyllaPiotr ScyllaPiotr commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add set_listen_backlog(int) to the server_socket class hierarchy, allowing the listen backlog to be changed on an already-listening socket
  • On Linux, this re-invokes the listen() syscall on the underlying file descriptor, which is supported for bound sockets
  • Also add set_listen_backlog() to http_server, which iterates all active listeners and updates their backlog

Details

The virtual method is added to server_socket_impl with a no-op default. The POSIX implementations (posix_server_socket_impl and posix_reuseport_server_socket_impl) override it to call _lfd.get_file_desc().listen(backlog). The public API is exposed through server_socket::set_listen_backlog() and http_server::set_listen_backlog().

This is needed by ScyllaDB's Alternator to support live-updating the listen socket backlog configuration at runtime.

Comment thread include/seastar/net/posix-stack.hh Outdated
virtual future<accept_result> accept() override;
virtual void abort_accept() override;
virtual socket_address local_address() const override;
virtual void set_listen_backlog(int backlog) override { _lfd.get_file_desc().listen(backlog); }

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.

Shouldn't TLS socket also get its set_listen_backlog() override?

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.

Good catch, added the forwarding override in server_session so TLS sockets delegate to the underlying socket.

@ScyllaPiotr ScyllaPiotr force-pushed the fix-ent-5614-seastar branch from e33e081 to 4fb87e3 Compare March 31, 2026 12:07
Comment thread include/seastar/net/posix-stack.hh Outdated
virtual future<accept_result> accept() override;
virtual void abort_accept() override;
virtual socket_address local_address() const override;
virtual void set_listen_backlog(int backlog) override { _lfd.get_file_desc().listen(backlog); }

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.

Please move the implementation to .cc to reduce include load.

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.

Done. Moved both posix_server_socket_impl::set_listen_backlog and posix_reuseport_server_socket_impl::set_listen_backlog implementations to posix-stack.cc, consistent with the other methods in those classes.

Comment thread include/seastar/net/stack.hh Outdated
/// The default implementation is a no-op; POSIX implementations
/// re-invoke the listen() syscall which Linux supports on a
/// bound socket.
virtual void set_listen_backlog(int backlog) {}

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.

Just like that?

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.

Changed the default to log a warning instead of silently no-op'ing, following the pattern in native-stack-impl.hh where unsupported operations (e.g. Reuseaddr is not supported by native stack) are logged. The implementation is now in stack.cc, keeping the header clean.

@ScyllaPiotr ScyllaPiotr force-pushed the fix-ent-5614-seastar branch from 4fb87e3 to 2754899 Compare April 1, 2026 07:29
@nyh

nyh commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

@ScyllaPiotr there are merge conflicts.

@nyh

nyh commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

By the way, this is a single-patch commit so its cover letter gets ignored and isn't saved in the git log. If there is any important information in the cover letter you wish to save, please copy to the commit message of the single patch. Thanks.

@nyh nyh 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.

Looks good to me, but you are missing a test.

If you tested this externally (e.g., in ScyllaDB) it will be good to say so, but even better would be to add a unit test. Should be fairly easy - create a server with opts.listen_backlog = 42, confirm the listen_backlog is 42, then set_listen_backlog(67) and check that listen_backlog changed to 67.

By the way, do we actually have a function get_server_backlog() to use in that test? If we don't, this test will help you realize that we're missing this ;-)

Comment thread include/seastar/net/stack.hh Outdated
virtual void abort_accept() = 0;
virtual socket_address local_address() const = 0;
/// Update the listen backlog on an already-listening socket.
/// The default implementation logs a warning; POSIX implementations

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.

Nitpick: I don't think the superclass should document how the subclasses handle this API. The word "default implementation" is even misleading - the default socket is the Posix one, the superclass is not really "default", it's just a superclass that nobody should be using directly.

Add set_listen_backlog(int) to the server_socket API and expose the same operation through http_server so active listeners can be updated after listen().

Add get_listen_backlog() for observability/testing, implement it in POSIX server socket implementations by tracking the configured backlog, and forward it through TLS server sockets.

On POSIX sockets, set_listen_backlog() re-invokes listen(backlog) on the listening file descriptor. Add a unit test that verifies runtime update of the configured backlog value (1111 -> 1888).
@ScyllaPiotr ScyllaPiotr force-pushed the fix-ent-5614-seastar branch from 2754899 to 09606fe Compare April 1, 2026 12:47
@ScyllaPiotr

ScyllaPiotr commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 09606fe:

  • Rebased and resolved conflicts
  • Updated superclass API comment wording in server_socket_impl
  • Added get_listen_backlog() plumbing (including TLS forwarding)
  • Added unit test socket_listen_backlog_runtime_update_test that verifies runtime update (1111 -> 1888)
  • Expanded single-commit message with important implementation details

Local verification:
./build/dev/seastar/tests/unit/socket_test --run_test=socket_listen_backlog_runtime_update_test -- -c 2 --reactor-backend linux-aio

@nyh please take another look when convenient.

@ScyllaPiotr

Copy link
Copy Markdown
Contributor Author

@avikivity please re-review

@ScyllaPiotr

Copy link
Copy Markdown
Contributor Author

Addressed in 09606fe:

* Rebased and resolved conflicts

* Updated superclass API comment wording in server_socket_impl

* Added get_listen_backlog() plumbing (including TLS forwarding)

* Added unit test socket_listen_backlog_runtime_update_test that verifies runtime update (1111 -> 1888)

* Expanded single-commit message with important implementation details

Local verification: ./build/dev/seastar/tests/unit/socket_test --run_test=socket_listen_backlog_runtime_update_test -- -c 2 --reactor-backend linux-aio

@nyh please take another look when convenient.

@nyh please re-review.

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.

4 participants