Fix error handling when creating clients (mp::ConnectStream) - #298
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
ConnectStream
|
Thanks for following up to #183 with these tests. They do seem potentially useful. Here is feedback I'd have:
Overall the tests here seem reasonable to add. It seems good to have at least 1-2 tests verifying disconnects are processed when a capnproto client connects to a non-capnproto server. (Relatedly, there are also other disconnect tests that could be added at different points during capnproto connections, which I started to write in #201 (comment) and https://github.com/ryanofsky/libmultiprocess/commits/pr/distest.2 but was never able to really finish due to complexity of trying to set up and cover all of the relevant cases. Just mentioning this for completeness, though. There's probably not an obviously place to follow up with this at the moment.) |
d3390db to
cdada78
Compare
cdada78 to
4f05dbe
Compare
595e258 to
bc85c9a
Compare
ConnectStreamConnectStream
02b300c to
7c24708
Compare
|
Thanks for the feedback @ryanofsky! I've just rebased to master now that #269 has been merged and added a new commit to move Also, I've made changes to the tests (please check the description), keeping the first 2 tests (Notice that I've dropped the
This is my current focus. I'm looking more into it, but I think this work might need its own branch so we keep test coverage scoped to this PR.
Good, these ideas are great and definitely worth exploring. Happy to tackle them after this. |
|
This PR is now ready for review. I've updated the description as well! |
02f2822 to
bd3c83d
Compare
9078674 to
a2e0007
Compare
e4530f8 to
f3355b5
Compare
|
Rebased on master which now includes #274. Adapted the tests to the stream API ( |
ryanofsky
left a comment
There was a problem hiding this comment.
Code review f3355b5. I need to take more time to understand the tests but the bugfix looks right and useful for improving the stability of the C++ IPC client if it connects to a server that disconnects right away.
I left a minor suggestion below. Also would note that this conflicts with #231 and while I think conflicts mostly just come from moved code, it could be useful to try merging the two PRs and making sure the new tests do not introduce any unix-isms.
| passDataPointers @22 (arg :List(Data)) -> (result :List(Data)); | ||
| } | ||
|
|
||
| interface FooInit $Proxy.wrap("mp::test::FooInit") { |
There was a problem hiding this comment.
In commit "Add test coverage for ConnectStream" (31c1ac2)
Am curious why this new FooInit interface is needed and existing Foo interface isn't used.
It also seems like a potentially complicating factor that could make the tests harder to debug & understand for this to have a construct method. I wonder if it could be dropped or at least the Thread map parameters could be dropped since it doesn't look like anything in these tests requires threadmaps
EDIT: Oh, I see in next commit it looks like there are new tests that rely on the construct call failing. I think it would be to only use the FooInit type for the tests which actually need the construct method, and use FooInterface for other tests. Also would be good to drop ThreadMap parameters as I believe they should not be needed.
There was a problem hiding this comment.
Nice suggestion!
I addressed it in 44d1914 by removing the ThreadMap parameters.
There was a problem hiding this comment.
Regarding the FooInit/FooInterface split, the tests already follow this. Only the 4 tests that require the construct() call use FooInit.
Also, I've replaced the initThreadMap call with a simple add(1, 2) in the "ConnectStream defers disconnect failure to the first IPC request for interfaces without construct()" test case.
…ctions` 496fb84 test: cover immediate client disconnects for `ListenConnections` (xyzconstant) 140d9ba test: allow custom log handler in `ListenSetup` (xyzconstant) Pull request description: Following on testing the reversed direction *ryanofsky* [suggested](#298 (comment)) in #298, this PR adds a test to cover immediate client disconnects on the server side. Additionally, this test adds `DefaultLogHandler` and a `log_handler` parameter to `ListenSetup`, allowing individual tests to observe logs by passing a custom log handler. The new test takes advantage of this by catching and skipping `Uncaught exception in daemonized task.` logs. NOTE: an issue surfaced on the macOS job, the `accept()` call in `ListenConnections` [fails](https://github.com/bitcoin-core/libmultiprocess/actions/runs/29545518652/job/87776862017?pr=310) for the closed connection, this is a Cap'n Proto bug as reported by *ViniciusCestarii* in #310 (review) and its fix is [available](capnproto/capnproto@7df5bd0#diff-ec577ad66535f58f6d7396ea51d3e56c0065308aa8fb02751cd6a8cfaa67252fR1358-R1372) in the v2 branch. ACKs for top commit: ryanofsky: Code review ACK 496fb84. Since last review just tightened the checks to only allow the error on macos Tree-SHA512: 6347b433d03968541be58b893746f707ce905d0fe35ddfaa858439d73cc0850a9d5077a472ff6bad91c8de67fb3ef43e2b303dcf73c6e9d6ef555fce40327f96
c435ef7 to
8fb3b5b
Compare
A later commit will consume the `UnixListener` class in another test file, so move it to a shared one.
This commit introduces a new test file `connect_tests.cpp` for testing the `ConnectStream` function. It also adds a `FooInit` test interface declaring a `construct()` method, which `ConnectStream` calls implicitly when present.
Two bugs that have always been present: 1. `ConnectStream` registered the `onDisconnect` handler that deletes the `Connection` before the `ProxyClient` object owning it was created, so an early disconnect could delete the `Connection` while the client constructor was reading it (bitcoin-core#308). 2. A `construct()` method failing during client construction caused a `Connection` leak. Normally, cleanup happens in the destructor but a constructor that throws leaves no object behind, so it never runs, resulting in an event loop ref preventing `EventLoop::loop()` from exiting (bitcoin-core#309). Fix the first by making `ProxyClientBase` responsible for the connection when `destroy_connection` is true, registering the delete-on-disconnect handler at the end of its constructor. Fix the second by running the cleanup functions before rethrowing. Fixes bitcoin-core#308 Fixes bitcoin-core#309
|
Rebased with master and fixed surfaced IWYU issues. Additionally, addressed @ryanofsky's feedback by removing the |
8fb3b5b to
bb47369
Compare
Flagged by IWYU.
| class TestSetup | ||
| { | ||
| public: | ||
| int client_fd; |
There was a problem hiding this comment.
In commit "Add test coverage for ConnectStream" (44d1914)
All these class members should have m_ prefixes so it is clear when they are accessed from methods that they are class members and not local variables. Lack of prefixes also makes code confusing below because there are two different variables called loop
There was a problem hiding this comment.
Addressed this in 70467c5 (follow-up PR).
|
|
||
| //! Default event loop log handler used by tests, throws so the calling code | ||
| //! can assert on errors. | ||
| void DefaultLogHandler(mp::LogMessage log) |
There was a problem hiding this comment.
In commit "Add test coverage for ConnectStream" (44d1914)
This seems to be slightly different than the DefaultLogHandler defined in listen_tests.cpp. Would be nice to define a shared on, maybe in a test.h file.
There was a problem hiding this comment.
Nice suggestion! I moved this logger to a common.h file instead at ae5c6bc (follow-up PR).
| int client_fd; | ||
| int server_fd; | ||
|
|
||
| mp::EventLoop* loop; |
There was a problem hiding this comment.
In commit "Add test coverage for ConnectStream" (44d1914)
Would probably drop mp:: prefix throughout this file since tests are in the mp namespace.
There was a problem hiding this comment.
Nice, addressed at 5790bec (follow-up PR).
| }, | ||
| log_handler) {} | ||
|
|
||
| TestSetup(const std::function<void(int[2])>& init_sockets, |
There was a problem hiding this comment.
In commit "Add test coverage for ConnectStream" (44d1914)
Having the init_sockets callback and the client_fd and server_fd members seems unnecessarily complicated given that nothing else in the test setup class uses them. Would seem simpler to drop these
diff
--- a/test/mp/test/connect_tests.cpp
+++ b/test/mp/test/connect_tests.cpp
@@ -9,16 +9,15 @@
#include <kj/test.h>
#include <mp/proxy.h>
#include <mp/proxy-io.h>
+#include <mp/util.h>
#include <mp/test/foo.capnp.h>
#include <mp/test/foo.capnp.proxy.h>
#include <sys/socket.h>
-#include <sys/types.h>
#include <unistd.h>
#include <chrono>
#include <condition_variable>
#include <cstring> // IWYU pragma: keep
-#include <functional>
#include <future>
#include <memory>
#include <mutex>
@@ -45,9 +44,6 @@ void DefaultLogHandler(mp::LogMessage log)
class TestSetup
{
public:
- int client_fd;
- int server_fd;
-
mp::EventLoop* loop;
std::optional<mp::EventLoopRef> loop_ref;
//! Thread variable should be after other struct members so the thread does
@@ -55,14 +51,6 @@ public:
std::thread loop_thread;
TestSetup(mp::LogFn log_handler = DefaultLogHandler)
- : TestSetup(
- [](int fds[2]) {
- KJ_REQUIRE(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) != -1);
- },
- log_handler) {}
-
- TestSetup(const std::function<void(int[2])>& init_sockets,
- mp::LogFn log_handler = DefaultLogHandler)
{
std::promise<mp::EventLoop*> loop_promise;
loop_thread = std::thread([&, log_handler] {
@@ -72,13 +60,6 @@ public:
});
loop = loop_promise.get_future().get();
loop_ref.emplace(*loop);
-
- // Initialize and store sockets
- int fds[2] = {-1, -1};
- init_sockets(fds);
-
- client_fd = fds[0];
- server_fd = fds[1];
}
~TestSetup()
@@ -91,15 +72,16 @@ public:
KJ_TEST("ConnectStream connects to a socket serving a valid init interface")
{
TestSetup setup;
+ auto [client_fd, server_fd] = SocketPair();
- std::thread server_thread([&setup]() {
+ std::thread server_thread([&]() {
mp::EventLoop server_loop("mptest-valid-server", DefaultLogHandler);
std::unique_ptr<FooInit> init = std::make_unique<FooInit>();
- ServeStream<messages::FooInit>(server_loop, MakeStream(server_loop, setup.server_fd), *init);
+ ServeStream<messages::FooInit>(server_loop, MakeStream(server_loop, server_fd), *init);
server_loop.loop();
});
- auto init = ConnectStream<messages::FooInit>(*setup.loop, MakeStream(*setup.loop, setup.client_fd));
+ auto init = ConnectStream<messages::FooInit>(*setup.loop, MakeStream(*setup.loop, client_fd));
init.reset();
server_thread.join();
@@ -109,11 +91,12 @@ KJ_TEST("ConnectStream connects to a socket serving a valid init interface")
KJ_TEST("ConnectStream throws when the socket is already disconnected")
{
TestSetup setup;
+ auto [client_fd, server_fd] = SocketPair();
- close(setup.server_fd);
+ close(server_fd);
try {
- auto init = ConnectStream<messages::FooInit>(*setup.loop, MakeStream(*setup.loop, setup.client_fd));
+ auto init = ConnectStream<messages::FooInit>(*setup.loop, MakeStream(*setup.loop, client_fd));
KJ_EXPECT(false);
} catch (const std::runtime_error& e) {
@@ -126,12 +109,13 @@ KJ_TEST("ConnectStream throws when the socket is already disconnected")
KJ_TEST("ConnectStream defers disconnect failure to the first IPC request for interfaces without construct()")
{
TestSetup setup;
+ auto [client_fd, server_fd] = SocketPair();
- close(setup.server_fd);
+ close(server_fd);
// Without a construct() method no IPC call is made during client
// creation, so ConnectStream succeeds even though the peer is gone.
- auto foo = ConnectStream<messages::FooInterface>(*setup.loop, MakeStream(*setup.loop, setup.client_fd));
+ auto foo = ConnectStream<messages::FooInterface>(*setup.loop, MakeStream(*setup.loop, client_fd));
try {
foo->add(1, 2);
@@ -157,10 +141,11 @@ KJ_TEST("ConnectStream handles a disconnect when no client calls are made")
}
DefaultLogHandler(log);
});
+ auto [client_fd, server_fd] = SocketPair();
- close(setup.server_fd);
+ close(server_fd);
- auto foo = ConnectStream<messages::FooInterface>(*setup.loop, MakeStream(*setup.loop, setup.client_fd));
+ auto foo = ConnectStream<messages::FooInterface>(*setup.loop, MakeStream(*setup.loop, client_fd));
// The disconnect handler registered by ProxyClientBase should run and
// delete the connection even when no calls are ever made.
@@ -171,20 +156,21 @@ KJ_TEST("ConnectStream handles a disconnect when no client calls are made")
KJ_TEST("ConnectStream throws when the socket disconnects after receiving data")
{
TestSetup setup;
+ auto [client_fd, server_fd] = SocketPair();
- std::thread server_thread([&setup]() {
+ std::thread server_thread([&]() {
char buf[128];
ssize_t bytes_received =
- recv(setup.server_fd, buf, sizeof(buf), 0);
+ recv(server_fd, buf, sizeof(buf), 0);
if (bytes_received > 0) {
- close(setup.server_fd);
+ close(server_fd);
}
});
try {
- auto init = ConnectStream<messages::FooInit>(*setup.loop, MakeStream(*setup.loop, setup.client_fd));
+ auto init = ConnectStream<messages::FooInit>(*setup.loop, MakeStream(*setup.loop, client_fd));
if (server_thread.joinable()) server_thread.join();
KJ_EXPECT(false);
@@ -199,16 +185,14 @@ KJ_TEST("ConnectStream throws when the socket disconnects after receiving data")
KJ_TEST("ConnectStream throws when a connection accepted from a listener disconnects after receiving data")
{
UnixListener listener;
+ TestSetup setup;
+ int client_fd = listener.MakeConnectedSocket();
+ int server_fd = listener.release();
- TestSetup setup([&listener](int fds[2]) {
- fds[0] = listener.MakeConnectedSocket(); // client_fd
- fds[1] = listener.release(); // server_fd
- });
-
- std::thread server_thread([&setup]() {
+ std::thread server_thread([&]() {
char buf[128];
- int connection_fd = accept(setup.server_fd, nullptr, nullptr);
+ int connection_fd = accept(server_fd, nullptr, nullptr);
if (connection_fd >= 0) {
ssize_t bytes_received =
@@ -218,11 +202,11 @@ KJ_TEST("ConnectStream throws when a connection accepted from a listener disconn
close(connection_fd);
}
}
- close(setup.server_fd);
+ close(server_fd);
});
try {
- auto init = ConnectStream<messages::FooInit>(*setup.loop, MakeStream(*setup.loop, setup.client_fd));
+ auto init = ConnectStream<messages::FooInit>(*setup.loop, MakeStream(*setup.loop, client_fd));
if (server_thread.joinable()) server_thread.join();
KJ_EXPECT(false);There was a problem hiding this comment.
Yeah, you're right, having them was indeed unnecessary. Addressed this at 466afd0 (follow-up PR).
Thanks for the diff!
| try { | ||
| auto init = ConnectStream<messages::FooInit>(*setup.loop, MakeStream(*setup.loop, setup.client_fd)); | ||
|
|
||
| if (server_thread.joinable()) server_thread.join(); |
There was a problem hiding this comment.
In commit "Add test coverage for ConnectStream" (44d1914)
I don't think it makes sense to call joinable here and to repeat this same line. It would make more sense to simply call server_thread.join() unconditionally at the end of this function after the try/catch.
Same comment also applies to test below
There was a problem hiding this comment.
Nice catch. Addressed at 24f17bd (follow-up PR).
| server_loop.loop(); | ||
| }); | ||
|
|
||
| auto init = ConnectStream<messages::FooInit>(*setup.loop, MakeStream(*setup.loop, setup.client_fd)); |
There was a problem hiding this comment.
In commit "Add test coverage for ConnectStream" (44d1914)
Might be good to note in a comment that FooInit capnproto interface has a construct method, so this is not just connecting to the IPC server, but also testing that the construct IPC request completes successfully.
| { | ||
| TestSetup setup; | ||
|
|
||
| close(setup.server_fd); |
|
|
||
| std::string_view reason = e.what(); | ||
| KJ_EXPECT(reason == "IPC client method called after disconnect."); | ||
| KJ_EXPECT(reason == "IPC client method call interrupted by disconnect."); |
There was a problem hiding this comment.
In commit "Fix error handling when creating clients" (bb47369)
It would be helpful if commit message noted the reason existing tests in this commit are changing, that because the onDisconnect call now happens later, client code might detect disconnects happening during IPC calls instead of before them.
There was a problem hiding this comment.
Sorry, couldn't reword the commit in time. Thanks for the feedback, though.
|
|
||
| // The disconnect handler may delete the connection before the | ||
| // call is processed or while the call is in flight, both errors are possible. | ||
| KJ_EXPECT(reason == "IPC client method called after disconnect." || reason == "IPC client method call interrupted by disconnect."); |
There was a problem hiding this comment.
In commit "Fix error handling when creating clients" (bb47369)
I'm confused about this change. I don't understand if disconnects are detected later now, why the "interrupted by disconnect" message would change to an "interrupted after connect". Would be good to have a more specific comment explaining this, or possibly reverting the change here if not necessary.
EDIT: Reason for this changes seems to be that test.cpp does not use ConnectStream so no disconnect handler was ever registered previously, and now one is registed since the disconnect handler was moved to ProxyClientBase. Would be helpful if commit message mentioned that as reason this test is changing.
|
Thanks for the review @ryanofsky! Unfortunately, I couldn't address your feedback in time before this PR was merged. Opened a follow-up PR to address your suggestions: #344. I replied to some of your inline comments with links to the commit in the follow-up PR that tackles it. |
c39c785 doc: note construct() call in valid init interface test (xyzconstant) b9c36c6 test: close sockets unconditionally and check errors with KJ_SYSCALL (xyzconstant) 7eb741e test: drop unnecessary KJ_EXPECT(true) (xyzconstant) 113f1d4 test: join server thread unconditionally in connect tests (xyzconstant) 44bc463 test: drop mp:: prefixes in connect tests (xyzconstant) 038d33e test: share DefaultLogHandler between test files (xyzconstant) b54a163 test: drop TestSetup socket members in connect tests (xyzconstant) 70467c5 test: add m_ prefix to TestSetup members in connect tests (xyzconstant) cc260f2 test: replace capnp fix link with upstream PR (xyzconstant) Pull request description: Addresses review suggestions left (all of them made by ryanofsky) in the now-merged PRs #298 and #310. These are non-critical test cleanups (naming, simplification, comments, etc.) with zero changes to library code. ACKs for top commit: ryanofsky: Code review ACK c39c785. Thanks for the followup! Tree-SHA512: e703d4508f46978c0be7831d3be04c831829aa5de08873e93fbe4ba02b0a5db71554fd80c30058336a4b3f3a620f496d5fb4bfee66f99fc24234073fa98db4c4
d0eea62c58 ci: add Windows cross-compilation config using MinGW and Wine ae6cf017d4 test: Add TCP SocketListener and Windows compat to socketlistener.h 1938c199d7 util: make pthreads optional on Windows to enable MSVC builds 97011d4008 util: Fix Windows SpawnProcess hang when child exits before connecting to named pipe 7861351f24 util: Add Windows support ee09c2b269 util: Add Windows CommandLineFromArgv escaping function 860e2ffb5c util, test: guard Unix-only code for Windows build c79b49afe1 util, test: Replace UnixListener with SocketListener 15aa914f03 util, test: Add CloseSocket, use SocketId be5f87655a util: Improve SpawnProcess API and documentation 390b5f901f Merge bitcoin-core/libmultiprocess#344: test: listen_tests and connect_tests follow-ups e18ca520f4 Merge bitcoin-core/libmultiprocess#343: test: fix race in connect_tests disconnect-deferred-failure test c39c7850c6 doc: note construct() call in valid init interface test b9c36c6175 test: close sockets unconditionally and check errors with KJ_SYSCALL 7eb741e635 test: drop unnecessary KJ_EXPECT(true) 113f1d4d28 test: join server thread unconditionally in connect tests 44bc4630bc test: drop mp:: prefixes in connect tests 038d33eb31 test: share DefaultLogHandler between test files b54a163308 test: drop TestSetup socket members in connect tests 70467c5a72 test: add m_ prefix to TestSetup members in connect tests cc260f2526 test: replace capnp fix link with upstream PR 137a6e4e03 test: fix race in connect_tests disconnect-deferred-failure test 8dab0d4bde Merge bitcoin-core/libmultiprocess#341: ci: add -Wextra-semi to llvm config b3b134eed8 ci: add -Wextra-semi to llvm config bdd0cd6941 Merge bitcoin-core/libmultiprocess#339: refactor: add `[[noreturn]]` attributes a779a09764 ci: add -Wmissing-noreturn 636aaff576 refactor: add missing [[noreturn]] attributes cc11c2b1b4 Merge bitcoin-core/libmultiprocess#338: test: check ReadList return value 2d6e863c77 Merge bitcoin-core/libmultiprocess#334: ci: Set CMAKE_BUILD_PARALLEL_LEVEL to enable parallelism by default d4d10ff98a Merge bitcoin-core/libmultiprocess#332: ci: add -Wextra-semi to default config b540e70f25 Merge bitcoin-core/libmultiprocess#324: proxy: Name threads spawned by the event loop e5e367e785 Merge bitcoin-core/libmultiprocess#312: util: report back child errors to parent and throw 2220df68c9 Merge bitcoin-core/libmultiprocess#298: Fix error handling when creating clients (`mp::ConnectStream`) 51defb79ef Merge bitcoin-core/libmultiprocess#340: ci: Update `capnproto` prerequisites on NetBSD 7e94790b08 ci: Update `capnproto` prerequisites on NetBSD 9f25ffca5b test: Cover OS thread names for worker, pool, and async threads 648a18589c proxy: Name threads spawned by the event loop 49834b2609 ci: add -Wextra-semi to default config fae9a637e3 example: Remove unused kj/async.h include bb473690c9 Fix error handling when creating clients 44d191420c Add test coverage for ConnectStream 231361ae5a Correct stale UnixListener doc comment 060c1a50d0 Extract `UnixListener` class to a dedicated file 62f25af06c test: check ReadList return value ce51d73725 ci: Set CMAKE_BUILD_PARALLEL_LEVEL to enable parallism in build jobs by default 67302cd132 Merge bitcoin-core/libmultiprocess#331: Remove code for Cap'n Proto versions before 0.9 f13c64ab54 Merge bitcoin-core/libmultiprocess#330: ci: Compile with minimum supported g++ in olddeps 8e026f6625 Merge bitcoin-core/libmultiprocess#327: build: avoid unnecessary capnp-rpc dependency for mpgen e5206e9eb5 Merge bitcoin-core/libmultiprocess#325: cmake: Remove `QUIET` option from `find_package(CapnProto ...)` 879efea2bc Merge bitcoin-core/libmultiprocess#321: ci: Roll NetBSD releases to 11.0, drop 9.4 abf127a314 Merge bitcoin-core/libmultiprocess#317: ipc: Fix mpgen capnp tool path for vcpkg/Windows builds c437d7f107 Merge bitcoin-core/libmultiprocess#310: test: cover immediate client disconnects for `ListenConnections` 31bff8a673 Merge bitcoin-core/libmultiprocess#307: refactor: memcpy -> std::ranges::copy f355108b0a Merge bitcoin-core/libmultiprocess#303: type-chrono: Add CustomBuildField/CustomReadField overloads for std::chrono::time_point 2d678177c1 Merge bitcoin-core/libmultiprocess#296: ci: Bump channel to nixos-26.05 3f05b11624 util: kill and reap child on SpawnProcess error 4a56c1837a util: report back child error to parent and throw a9e70dbe77 ci: Add NetBSD release 11.0 2d33b14fb0 ci: Switch to default compiler on NetBSD 9.4 36f7400277 ci: Drop NetBSD release 9.4 bd508311b5 refactor: Drop stray semicolons after function definitions 788f17a850 Remove code for Cap'n Proto versions before 0.9 7402affd0c ci: Pin oldeps config to older nixpkgs channel to compile older cmake with older gcc edf6343562 ci: Compile with minimum supported g++-11 in olddeps fa47449afe cmake: avoid unnecessary capnp-rpc dependency for mpgen a494b764de cmake: Remove `QUIET` option from `find_package(CapnProto ...)` 26452e02d7 refactor: memcpy -> std::ranges::copy e1dcc6eb18 Merge bitcoin-core/libmultiprocess#316: cmake: Fix stale codegen when mpgen binary changes 7a72df02e2 type-chrono: Add CustomBuildField/CustomReadField overloads for std::chrono::time_point 45b685c3f5 type-number, type-chrono: Fix static assert signed/unsigned comparisons 45f6255975 type-number: exclude bool from the integral overload 8d6d464948 Merge bitcoin-core/libmultiprocess#315: Fix startup race in example a6fc80d254 Merge bitcoin-core/libmultiprocess#311: bugfix: clear FD_CLOEXEC in child instead of parent before fork 496fb84e69 test: cover immediate client disconnects for `ListenConnections` 36c6c63520 doc: Document reference-counted EventLoop lifetime 3a997e113c Fix startup race in mpexample f5c15ce33f Merge bitcoin-core/libmultiprocess#323: refactor: access ThreadContext through CurrentThread(), ci: switch Bitcoin Core to master 66298c737f ci: Switch back to Bitcoin Core's master branch 86b4810501 refactor: access ThreadContext through CurrentThread() eea9c64f6e cmake: Fix stale codegen when mpgen binary changes a26a08496b cmake: Fix mpgen capnp tool path for vcpkg/Windows builds 140d9ba6ff test: allow custom log handler in `ListenSetup` 1e0c7ff9a5 util: Clear FD_CLOEXEC in child instead of parent before fork 8550ee6a31 util, refactor: Add ChildFail helper for post-fork child errors 17eab90b52 test: Fix typo in listen_tests.cpp ce865a9ba8 refactor: Directly use value in CustomBuildField 3f221b5bfd Merge bitcoin-core/libmultiprocess#274: Add nonunix platform support 1b0f605606 doc: Remove trailing whitespace d8f8ca3119 ipc: Wrap mpgen main() in try-catch to print errors fbe5a14ad4 ci: Check out bitcoin/bitcoin PR #35084 instead of master 39d3690d83 types: Replace SFINAE with requires clauses to avoid MSVC C2039 error ba68520203 proxy, refactor: Fix C4305 truncation warning in Accessor on MSVC 1d81d47811 util, refactor: Fix PtrOrValue constructor for move-only types on MSVC b883fe1e52 proxy: Fix shutdownWrite() exception handling on macOS with dynamic libraries 0012411ccc proxy: Call shutdownWrite() in Connection destructor 38312ad191 proxy, refactor: Change ConnectStream and ServeStream to accept stream objects e96d5d742a proxy, refactor: Replace EventLoop wakeup fd integers with KJ stream objects db4f9a3d73 cmake: Bump minimum required Cap'n Proto version to 0.9 652934fb79 util, refactor: Add SocketPair() and use it in SpawnProcess 1c6ef7a26c util, refactor: Do not fork() and exec() separately 1389cf3132 util, refactor: Add SpawnConnectInfo type alias and use it c7ca1f00b6 util, refactor: Add SocketId type alias and use it be46a35203 util, refactor: Add ProcessId type alias and use it 91a78db780 doc: Bump version 13 > 14 fa2c56ec27 ci: Bump channel to nixos-26.05 git-subtree-dir: src/ipc/libmultiprocess git-subtree-split: d0eea62c58928f9660b8dc5541a62ea395c565ef
d0eea62c58 ci: add Windows cross-compilation config using MinGW and Wine ae6cf017d4 test: Add TCP SocketListener and Windows compat to socketlistener.h 1938c199d7 util: make pthreads optional on Windows to enable MSVC builds 97011d4008 util: Fix Windows SpawnProcess hang when child exits before connecting to named pipe 7861351f24 util: Add Windows support ee09c2b269 util: Add Windows CommandLineFromArgv escaping function 860e2ffb5c util, test: guard Unix-only code for Windows build c79b49afe1 util, test: Replace UnixListener with SocketListener 15aa914f03 util, test: Add CloseSocket, use SocketId be5f87655a util: Improve SpawnProcess API and documentation 390b5f901f Merge bitcoin-core/libmultiprocess#344: test: listen_tests and connect_tests follow-ups e18ca520f4 Merge bitcoin-core/libmultiprocess#343: test: fix race in connect_tests disconnect-deferred-failure test c39c7850c6 doc: note construct() call in valid init interface test b9c36c6175 test: close sockets unconditionally and check errors with KJ_SYSCALL 7eb741e635 test: drop unnecessary KJ_EXPECT(true) 113f1d4d28 test: join server thread unconditionally in connect tests 44bc4630bc test: drop mp:: prefixes in connect tests 038d33eb31 test: share DefaultLogHandler between test files b54a163308 test: drop TestSetup socket members in connect tests 70467c5a72 test: add m_ prefix to TestSetup members in connect tests cc260f2526 test: replace capnp fix link with upstream PR 137a6e4e03 test: fix race in connect_tests disconnect-deferred-failure test 8dab0d4bde Merge bitcoin-core/libmultiprocess#341: ci: add -Wextra-semi to llvm config b3b134eed8 ci: add -Wextra-semi to llvm config bdd0cd6941 Merge bitcoin-core/libmultiprocess#339: refactor: add `[[noreturn]]` attributes a779a09764 ci: add -Wmissing-noreturn 636aaff576 refactor: add missing [[noreturn]] attributes cc11c2b1b4 Merge bitcoin-core/libmultiprocess#338: test: check ReadList return value 2d6e863c77 Merge bitcoin-core/libmultiprocess#334: ci: Set CMAKE_BUILD_PARALLEL_LEVEL to enable parallelism by default d4d10ff98a Merge bitcoin-core/libmultiprocess#332: ci: add -Wextra-semi to default config b540e70f25 Merge bitcoin-core/libmultiprocess#324: proxy: Name threads spawned by the event loop e5e367e785 Merge bitcoin-core/libmultiprocess#312: util: report back child errors to parent and throw 2220df68c9 Merge bitcoin-core/libmultiprocess#298: Fix error handling when creating clients (`mp::ConnectStream`) 51defb79ef Merge bitcoin-core/libmultiprocess#340: ci: Update `capnproto` prerequisites on NetBSD 7e94790b08 ci: Update `capnproto` prerequisites on NetBSD 9f25ffca5b test: Cover OS thread names for worker, pool, and async threads 648a18589c proxy: Name threads spawned by the event loop 49834b2609 ci: add -Wextra-semi to default config fae9a637e3 example: Remove unused kj/async.h include bb473690c9 Fix error handling when creating clients 44d191420c Add test coverage for ConnectStream 231361ae5a Correct stale UnixListener doc comment 060c1a50d0 Extract `UnixListener` class to a dedicated file 62f25af06c test: check ReadList return value ce51d73725 ci: Set CMAKE_BUILD_PARALLEL_LEVEL to enable parallism in build jobs by default 67302cd132 Merge bitcoin-core/libmultiprocess#331: Remove code for Cap'n Proto versions before 0.9 f13c64ab54 Merge bitcoin-core/libmultiprocess#330: ci: Compile with minimum supported g++ in olddeps 8e026f6625 Merge bitcoin-core/libmultiprocess#327: build: avoid unnecessary capnp-rpc dependency for mpgen e5206e9eb5 Merge bitcoin-core/libmultiprocess#325: cmake: Remove `QUIET` option from `find_package(CapnProto ...)` 879efea2bc Merge bitcoin-core/libmultiprocess#321: ci: Roll NetBSD releases to 11.0, drop 9.4 abf127a314 Merge bitcoin-core/libmultiprocess#317: ipc: Fix mpgen capnp tool path for vcpkg/Windows builds c437d7f107 Merge bitcoin-core/libmultiprocess#310: test: cover immediate client disconnects for `ListenConnections` 31bff8a673 Merge bitcoin-core/libmultiprocess#307: refactor: memcpy -> std::ranges::copy f355108b0a Merge bitcoin-core/libmultiprocess#303: type-chrono: Add CustomBuildField/CustomReadField overloads for std::chrono::time_point 2d678177c1 Merge bitcoin-core/libmultiprocess#296: ci: Bump channel to nixos-26.05 3f05b11624 util: kill and reap child on SpawnProcess error 4a56c1837a util: report back child error to parent and throw a9e70dbe77 ci: Add NetBSD release 11.0 2d33b14fb0 ci: Switch to default compiler on NetBSD 9.4 36f7400277 ci: Drop NetBSD release 9.4 bd508311b5 refactor: Drop stray semicolons after function definitions 788f17a850 Remove code for Cap'n Proto versions before 0.9 7402affd0c ci: Pin oldeps config to older nixpkgs channel to compile older cmake with older gcc edf6343562 ci: Compile with minimum supported g++-11 in olddeps fa47449afe cmake: avoid unnecessary capnp-rpc dependency for mpgen a494b764de cmake: Remove `QUIET` option from `find_package(CapnProto ...)` 26452e02d7 refactor: memcpy -> std::ranges::copy e1dcc6eb18 Merge bitcoin-core/libmultiprocess#316: cmake: Fix stale codegen when mpgen binary changes 7a72df02e2 type-chrono: Add CustomBuildField/CustomReadField overloads for std::chrono::time_point 45b685c3f5 type-number, type-chrono: Fix static assert signed/unsigned comparisons 45f6255975 type-number: exclude bool from the integral overload 8d6d464948 Merge bitcoin-core/libmultiprocess#315: Fix startup race in example a6fc80d254 Merge bitcoin-core/libmultiprocess#311: bugfix: clear FD_CLOEXEC in child instead of parent before fork 496fb84e69 test: cover immediate client disconnects for `ListenConnections` 36c6c63520 doc: Document reference-counted EventLoop lifetime 3a997e113c Fix startup race in mpexample f5c15ce33f Merge bitcoin-core/libmultiprocess#323: refactor: access ThreadContext through CurrentThread(), ci: switch Bitcoin Core to master 66298c737f ci: Switch back to Bitcoin Core's master branch 86b4810501 refactor: access ThreadContext through CurrentThread() eea9c64f6e cmake: Fix stale codegen when mpgen binary changes a26a08496b cmake: Fix mpgen capnp tool path for vcpkg/Windows builds 140d9ba6ff test: allow custom log handler in `ListenSetup` 1e0c7ff9a5 util: Clear FD_CLOEXEC in child instead of parent before fork 8550ee6a31 util, refactor: Add ChildFail helper for post-fork child errors 17eab90b52 test: Fix typo in listen_tests.cpp ce865a9ba8 refactor: Directly use value in CustomBuildField 3f221b5bfd Merge bitcoin-core/libmultiprocess#274: Add nonunix platform support 1b0f605606 doc: Remove trailing whitespace d8f8ca3119 ipc: Wrap mpgen main() in try-catch to print errors fbe5a14ad4 ci: Check out bitcoin/bitcoin PR #35084 instead of master 39d3690d83 types: Replace SFINAE with requires clauses to avoid MSVC C2039 error ba68520203 proxy, refactor: Fix C4305 truncation warning in Accessor on MSVC 1d81d47811 util, refactor: Fix PtrOrValue constructor for move-only types on MSVC b883fe1e52 proxy: Fix shutdownWrite() exception handling on macOS with dynamic libraries 0012411ccc proxy: Call shutdownWrite() in Connection destructor 38312ad191 proxy, refactor: Change ConnectStream and ServeStream to accept stream objects e96d5d742a proxy, refactor: Replace EventLoop wakeup fd integers with KJ stream objects db4f9a3d73 cmake: Bump minimum required Cap'n Proto version to 0.9 652934fb79 util, refactor: Add SocketPair() and use it in SpawnProcess 1c6ef7a26c util, refactor: Do not fork() and exec() separately 1389cf3132 util, refactor: Add SpawnConnectInfo type alias and use it c7ca1f00b6 util, refactor: Add SocketId type alias and use it be46a35203 util, refactor: Add ProcessId type alias and use it 91a78db780 doc: Bump version 13 > 14 fa2c56ec27 ci: Bump channel to nixos-26.05 git-subtree-dir: src/ipc/libmultiprocess git-subtree-split: d0eea62c58928f9660b8dc5541a62ea395c565ef
d0eea62c58 ci: add Windows cross-compilation config using MinGW and Wine ae6cf017d4 test: Add TCP SocketListener and Windows compat to socketlistener.h 1938c199d7 util: make pthreads optional on Windows to enable MSVC builds 97011d4008 util: Fix Windows SpawnProcess hang when child exits before connecting to named pipe 7861351f24 util: Add Windows support ee09c2b269 util: Add Windows CommandLineFromArgv escaping function 860e2ffb5c util, test: guard Unix-only code for Windows build c79b49afe1 util, test: Replace UnixListener with SocketListener 15aa914f03 util, test: Add CloseSocket, use SocketId be5f87655a util: Improve SpawnProcess API and documentation 390b5f901f Merge bitcoin-core/libmultiprocess#344: test: listen_tests and connect_tests follow-ups e18ca520f4 Merge bitcoin-core/libmultiprocess#343: test: fix race in connect_tests disconnect-deferred-failure test c39c7850c6 doc: note construct() call in valid init interface test b9c36c6175 test: close sockets unconditionally and check errors with KJ_SYSCALL 7eb741e635 test: drop unnecessary KJ_EXPECT(true) 113f1d4d28 test: join server thread unconditionally in connect tests 44bc4630bc test: drop mp:: prefixes in connect tests 038d33eb31 test: share DefaultLogHandler between test files b54a163308 test: drop TestSetup socket members in connect tests 70467c5a72 test: add m_ prefix to TestSetup members in connect tests cc260f2526 test: replace capnp fix link with upstream PR 137a6e4e03 test: fix race in connect_tests disconnect-deferred-failure test 8dab0d4bde Merge bitcoin-core/libmultiprocess#341: ci: add -Wextra-semi to llvm config b3b134eed8 ci: add -Wextra-semi to llvm config bdd0cd6941 Merge bitcoin-core/libmultiprocess#339: refactor: add `[[noreturn]]` attributes a779a09764 ci: add -Wmissing-noreturn 636aaff576 refactor: add missing [[noreturn]] attributes cc11c2b1b4 Merge bitcoin-core/libmultiprocess#338: test: check ReadList return value 2d6e863c77 Merge bitcoin-core/libmultiprocess#334: ci: Set CMAKE_BUILD_PARALLEL_LEVEL to enable parallelism by default d4d10ff98a Merge bitcoin-core/libmultiprocess#332: ci: add -Wextra-semi to default config b540e70f25 Merge bitcoin-core/libmultiprocess#324: proxy: Name threads spawned by the event loop e5e367e785 Merge bitcoin-core/libmultiprocess#312: util: report back child errors to parent and throw 2220df68c9 Merge bitcoin-core/libmultiprocess#298: Fix error handling when creating clients (`mp::ConnectStream`) 51defb79ef Merge bitcoin-core/libmultiprocess#340: ci: Update `capnproto` prerequisites on NetBSD 7e94790b08 ci: Update `capnproto` prerequisites on NetBSD 9f25ffca5b test: Cover OS thread names for worker, pool, and async threads 648a18589c proxy: Name threads spawned by the event loop 49834b2609 ci: add -Wextra-semi to default config fae9a637e3 example: Remove unused kj/async.h include bb473690c9 Fix error handling when creating clients 44d191420c Add test coverage for ConnectStream 231361ae5a Correct stale UnixListener doc comment 060c1a50d0 Extract `UnixListener` class to a dedicated file 62f25af06c test: check ReadList return value ce51d73725 ci: Set CMAKE_BUILD_PARALLEL_LEVEL to enable parallism in build jobs by default 67302cd132 Merge bitcoin-core/libmultiprocess#331: Remove code for Cap'n Proto versions before 0.9 f13c64ab54 Merge bitcoin-core/libmultiprocess#330: ci: Compile with minimum supported g++ in olddeps 8e026f6625 Merge bitcoin-core/libmultiprocess#327: build: avoid unnecessary capnp-rpc dependency for mpgen e5206e9eb5 Merge bitcoin-core/libmultiprocess#325: cmake: Remove `QUIET` option from `find_package(CapnProto ...)` 879efea2bc Merge bitcoin-core/libmultiprocess#321: ci: Roll NetBSD releases to 11.0, drop 9.4 abf127a314 Merge bitcoin-core/libmultiprocess#317: ipc: Fix mpgen capnp tool path for vcpkg/Windows builds c437d7f107 Merge bitcoin-core/libmultiprocess#310: test: cover immediate client disconnects for `ListenConnections` 31bff8a673 Merge bitcoin-core/libmultiprocess#307: refactor: memcpy -> std::ranges::copy f355108b0a Merge bitcoin-core/libmultiprocess#303: type-chrono: Add CustomBuildField/CustomReadField overloads for std::chrono::time_point 2d678177c1 Merge bitcoin-core/libmultiprocess#296: ci: Bump channel to nixos-26.05 3f05b11624 util: kill and reap child on SpawnProcess error 4a56c1837a util: report back child error to parent and throw a9e70dbe77 ci: Add NetBSD release 11.0 2d33b14fb0 ci: Switch to default compiler on NetBSD 9.4 36f7400277 ci: Drop NetBSD release 9.4 bd508311b5 refactor: Drop stray semicolons after function definitions 788f17a850 Remove code for Cap'n Proto versions before 0.9 7402affd0c ci: Pin oldeps config to older nixpkgs channel to compile older cmake with older gcc edf6343562 ci: Compile with minimum supported g++-11 in olddeps fa47449afe cmake: avoid unnecessary capnp-rpc dependency for mpgen a494b764de cmake: Remove `QUIET` option from `find_package(CapnProto ...)` 26452e02d7 refactor: memcpy -> std::ranges::copy e1dcc6eb18 Merge bitcoin-core/libmultiprocess#316: cmake: Fix stale codegen when mpgen binary changes 7a72df02e2 type-chrono: Add CustomBuildField/CustomReadField overloads for std::chrono::time_point 45b685c3f5 type-number, type-chrono: Fix static assert signed/unsigned comparisons 45f6255975 type-number: exclude bool from the integral overload 8d6d464948 Merge bitcoin-core/libmultiprocess#315: Fix startup race in example a6fc80d254 Merge bitcoin-core/libmultiprocess#311: bugfix: clear FD_CLOEXEC in child instead of parent before fork 496fb84e69 test: cover immediate client disconnects for `ListenConnections` 36c6c63520 doc: Document reference-counted EventLoop lifetime 3a997e113c Fix startup race in mpexample f5c15ce33f Merge bitcoin-core/libmultiprocess#323: refactor: access ThreadContext through CurrentThread(), ci: switch Bitcoin Core to master 66298c737f ci: Switch back to Bitcoin Core's master branch 86b4810501 refactor: access ThreadContext through CurrentThread() eea9c64f6e cmake: Fix stale codegen when mpgen binary changes a26a08496b cmake: Fix mpgen capnp tool path for vcpkg/Windows builds 140d9ba6ff test: allow custom log handler in `ListenSetup` 1e0c7ff9a5 util: Clear FD_CLOEXEC in child instead of parent before fork 8550ee6a31 util, refactor: Add ChildFail helper for post-fork child errors 17eab90b52 test: Fix typo in listen_tests.cpp ce865a9ba8 refactor: Directly use value in CustomBuildField 3f221b5bfd Merge bitcoin-core/libmultiprocess#274: Add nonunix platform support 1b0f605606 doc: Remove trailing whitespace d8f8ca3119 ipc: Wrap mpgen main() in try-catch to print errors fbe5a14ad4 ci: Check out bitcoin/bitcoin PR #35084 instead of master 39d3690d83 types: Replace SFINAE with requires clauses to avoid MSVC C2039 error ba68520203 proxy, refactor: Fix C4305 truncation warning in Accessor on MSVC 1d81d47811 util, refactor: Fix PtrOrValue constructor for move-only types on MSVC b883fe1e52 proxy: Fix shutdownWrite() exception handling on macOS with dynamic libraries 0012411ccc proxy: Call shutdownWrite() in Connection destructor 38312ad191 proxy, refactor: Change ConnectStream and ServeStream to accept stream objects e96d5d742a proxy, refactor: Replace EventLoop wakeup fd integers with KJ stream objects db4f9a3d73 cmake: Bump minimum required Cap'n Proto version to 0.9 652934fb79 util, refactor: Add SocketPair() and use it in SpawnProcess 1c6ef7a26c util, refactor: Do not fork() and exec() separately 1389cf3132 util, refactor: Add SpawnConnectInfo type alias and use it c7ca1f00b6 util, refactor: Add SocketId type alias and use it be46a35203 util, refactor: Add ProcessId type alias and use it 91a78db780 doc: Bump version 13 > 14 fa2c56ec27 ci: Bump channel to nixos-26.05 git-subtree-dir: src/ipc/libmultiprocess git-subtree-split: d0eea62c58928f9660b8dc5541a62ea395c565ef
Avoid use-after-free if the socket is disconnected before
ConnectStreamconnects (#308), and avoid leaks and hangs if clientconstruct()calls throw (#309). Also add tests to cover these and other client connection errors, as suggested by @ryanofsky.The following cases are tested:
ConnectStreamthrows during theconstruct()call)construct()(the failure is deferred to the first IPC request)accept()) that disconnects after some data arrivesAdditionally, a new
FooInittest interface is added, and theUnixListenerclass introduced in #269 is extracted to a shared file so the newconnect_tests.cppfile can use it.Note: Clients that own their connection now delete it on unexpected disconnects, so calls after a server disconnect fail with "called after disconnect" instead of "interrupted by disconnect" (one test.cpp assertion updated accordingly).