Skip to content

Return thread start failures from unix_socket and listener::create(place) - #243

Merged
skipbit merged 5 commits into
mainfrom
feat/ipc-thread-failures
Nov 23, 2026
Merged

skipbit merged 5 commits into
mainfrom
feat/ipc-thread-failures

Conversation

@skipbit

@skipbit skipbit commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

The threads that ipc::unix_socket and listener::create(place) start now go through start_thread(), so when the system will not start one, the error comes back as a value instead of std::system_error going through.

  • unix_socket::listen() returns std::errc::resource_unavailable_try_again when the system will not start the thread that waits on the socket, and std::errc::not_enough_memory when there is no memory to start it. A listen that fails this way leaves no socket file, and the place can be listened on again.
  • A connection made through unix_socket::connector() fails with the same errors when its thread does not start, and the connection lets go of everything it made.
  • listener::create(place) returns std::expected<listener, error> and fails when the thread that reaches the broadcaster does not start. listener::create(broadcaster) starts no thread and is unchanged. The example in listener.h and the gRPC consumer example in the workflow check the result.
  • listener and ipc::unix_socket are not in a release yet, so the changelog is unchanged.
  • The only not_enough_memory documented is the one from starting the thread; other allocations on these paths still throw std::bad_alloc.
  • start_thread() now takes the callable itself instead of a std::function, so wrapping a thread's body no longer allocates outside the handler that reports std::errc::not_enough_memory.

Testing

  • Linux, GCC 13: debug, release and AddressSanitizer builds without warnings; ctest passes 1191 of 1191 in each (1188 before, and 3 new tests).
  • Each commit builds without warnings and passes ctest on its own.
  • Running out of memory was checked outside the tests: with operator new throwing on the calling thread, start_thread() given a lambda that holds a shared_ptr returns std::errc::not_enough_memory, where the previous version let std::bad_alloc through.
  • A listen whose thread does not start returns the error, leaves no socket file, and a second listen at the same place succeeds. With the failure of the transport's thread start ignored, this test fails.
  • A connection whose thread does not start returns the error, and its events are not told of a close. With the failure ignored, the connection waits for ever (stopped by hand); with the connection still keeping itself after the failure, AddressSanitizer reports the leak and the test fails.
  • listener::create(place) returns the error when its thread does not start. With the failure of the connector's thread start ignored, the test fails.
  • clang-format 18.1.3 finds nothing, the examples compile with GCC and with Clang and libc++, and the changed sources pass -fsyntax-only with Clang and libc++ under -Wall -Wextra -Werror.
  • gRPC is not built here, so the change to test_grpc_notification.cpp and the gRPC consumer example in the workflow are checked by CI only.

listen() and each connection a connector makes start a thread that
waits on the socket. When the system will not start it, they now fail
with resource_unavailable_try_again, or not_enough_memory, instead of
letting the exception through. A failed listen leaves no socket file.
The connector of a listener made for a place starts a thread to reach
the broadcaster. create() now returns std::expected and fails when that
thread does not start, as unix_socket does.
start_thread() took a std::function, so wrapping the body allocated in
the caller, outside the handler that reports not_enough_memory, and
std::bad_alloc went through unix_socket and the connector of a
listener. It now takes the callable as it is and hands it to
std::thread, so what starting a thread allocates is reported.
Both ways a connection can fail before it is made drop the transport
and the reference that keeps the core going through one function.
@skipbit
skipbit merged commit 019feb6 into main Nov 23, 2026
38 checks passed
@skipbit
skipbit deleted the feat/ipc-thread-failures branch November 23, 2026 06:42
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.

1 participant