Fix error handling when creating clients (mp::ConnectStream)#298
Fix error handling when creating clients (mp::ConnectStream)#298xyzconstant wants to merge 4 commits into
mp::ConnectStream)#298Conversation
|
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. 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
a648c51 to
aee480b
Compare
Updated the description expanding more on this issue. |
0145706 to
96c32f3
Compare
|
Added the Updated the description with more details about it and included a fix in the second commit. |
|
Code review 96c32f3 Nice tests and fixes! The changes here look pretty good. I would just suggest a number of things to make this easier to understand and review:
|
fc5dbb8 to
8fdb95b
Compare
ConnectStreammp::ConnectStream)
7cd90ae to
fecf305
Compare
Next commit will consume the `UnixListener` class in another test file, so move it to a shared one.
9b93947 to
82f7ef2
Compare
|
re: #298 (comment) Thanks for the review @ryanofsky! Addressed your feedback and force-pushed, I hope the commit history is cleaner now. Opened issues (#308 and #309) and updated the PR title and description as well. Also, please note that I've added 2 new tests (I just noticed I pushed them right after your latest review, so you might have missed them), and I think they're valuable for showcasing the difference with an Init interface without |
This commit introduces a new test file `connect_tests.cpp` for testing the `ConnectStream` client method.
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
82f7ef2 to
9078674
Compare
|
🐙 This pull request conflicts with the target branch and needs rebase. |
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).