Skip to content

Non-blocking accept + mbedtls bugfix#582

Draft
Roytak wants to merge 6 commits intodevelfrom
non-blocking-accept
Draft

Non-blocking accept + mbedtls bugfix#582
Roytak wants to merge 6 commits intodevelfrom
non-blocking-accept

Conversation

@Roytak
Copy link
Collaborator

@Roytak Roytak commented Mar 13, 2026

Truly allow accepting new sessions from multiple threads.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables parallel nc_accept() usage by making listening sockets non-blocking and refactoring the accept/poll logic to be safe across multiple server accept threads. It also adds a dedicated concurrency-focused test and bumps the library micro version.

Changes:

  • Refactor server-side accept to poll/accept without per-bind mutexes by relying on non-blocking listening sockets.
  • Remove bind_lock/pollin state from internal bind structures and update call-home accept accordingly.
  • Add test_server_thread to validate parallel accept behavior and fix minor TLS errno checks.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/test_server_thread.c Adds a new cmocka test exercising parallel server accepts with multiple server/client threads.
tests/CMakeLists.txt Registers the new test_server_thread test target.
src/session_server.c Makes listening sockets non-blocking and introduces new pollfd-based concurrent accept helpers.
src/session_p.h Removes obsolete bind fields/locks and updates internal accept API declarations/comments.
src/session_client.c Updates call-home accept to use the new accept helper and removes the client CH bind lock.
src/session_client_tls.c Minor TLS handshake loop cleanup (uses the correct socket variable).
src/session_mbedtls.c Fixes errno checks (assignment → comparison) for WANT_READ/WANT_WRITE handling.
src/server_config.c Removes endpoint bind-lock initialization/destruction now that it’s no longer used.
CMakeLists.txt Bumps micro version/soversion to reflect internal changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +603 to 606
nc_sock_host_unix(int acc_sock_fd, char **host)
{
char *sun_path;
struct sockaddr_storage saddr;
Comment on lines +736 to +737
/* UNIX socket, get the socket path for logging */
unix_sockpath = nc_server_unix_get_socket_path(endpt);
return -1;
}

/* sucessfully accepted a connection! */
Comment on lines +105 to +109
nc_client_set_thread_context(state->client_thr_ctx);

pthread_barrier_wait(&state->start_barrier);

session = nc_connect_ssh("127.0.0.1", TEST_PORT, NULL);
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.

2 participants