Repository navigation
Return thread start failures from unix_socket and listener::create(place) - #243
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The threads that
ipc::unix_socketandlistener::create(place)start now go throughstart_thread(), so when the system will not start one, the error comes back as a value instead ofstd::system_errorgoing through.unix_socket::listen()returnsstd::errc::resource_unavailable_try_againwhen the system will not start the thread that waits on the socket, andstd::errc::not_enough_memorywhen 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.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)returnsstd::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 inlistener.hand the gRPC consumer example in the workflow check the result.listenerandipc::unix_socketare not in a release yet, so the changelog is unchanged.not_enough_memorydocumented is the one from starting the thread; other allocations on these paths still throwstd::bad_alloc.start_thread()now takes the callable itself instead of astd::function, so wrapping a thread's body no longer allocates outside the handler that reportsstd::errc::not_enough_memory.Testing
operator newthrowing on the calling thread,start_thread()given a lambda that holds ashared_ptrreturnsstd::errc::not_enough_memory, where the previous version letstd::bad_allocthrough.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.-fsyntax-onlywith Clang and libc++ under-Wall -Wextra -Werror.test_grpc_notification.cppand the gRPC consumer example in the workflow are checked by CI only.