-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix of socket inheriting (Win) #270
base: master
Are you sure you want to change the base?
Conversation
This commit closes an issue rpclib#259: If application starts another app and then exits (leaving second app running), listening socket created in first app is still alive (even after app exit), but this socket isn't used by anyone and even prevents to start listening again on the same port.
Hi, thanks for your contribution, this is part of asio's codebase, I'd not modify it except to update the asio version, or to cherry-pick a commit from their codebase. |
Hello! Okay, I understand. Probably it would be better to create pull request to asio. Thank you for reply. |
Maybe they already fixed it. In which case we can apply a similar patch you find the commit in asio that patched it ;) It's nice to fix that bug, I just don't want to apply patches to asio that have not been reviewed and accepted by the asio maintainers |
It is reasonable, agree. I'll try to investigate is there already this fix or otherwise will create PR there. https://github.com/boostorg/asio - Is it the source? |
Edit, just realized it might be a completely unrelated issue, I have opened a pull request for the issue below. I think it's an issue with using |
@thewhitegoatcb, @ihor-drachuk can you confirm this issue is gone now that I merged the patch on SO_REUSEADDR ? |
@qchateau, Hi! Thanks for attention to this problem.
Still if apply that workaround -- the problem goes away. |
Hum I don't expect you core to work. You start the new process when the 1st is still running so it's normal that it fails to bind, it's a sane behavior. How do you expect the 2nd process to tell that the 1st will exit soon ? |
Hence, it should work fine, because there is approx. 2 seconds of time between destroying So, we have "inherited" socket, which could not be used by rpclib, could not be closed and it's not possible to create server again on same port. Actually I would say socket "leaks", because there is no any chance that 2nd app instance could use it (particularly via rpclib), but this resource (socket, port) remains busy. Thus, if resource is inherited, but can't be used, accessed or released in any way, then it should not be inherited. I just tried to test and report if merged patch resolved an issue and... looks like no, unfortunately. Test-code is also tested by workaround, so, looks like you can trust this investigation. The only thing I'm not sure about is... is my workaround good solution in common or not (maybe not all cases/OSes are handled well) |
I run this test case on windows 11, the behavior is not expect as @ihor-drachuk say, the child process can create server successful.
|
Indeed, as @ihor-drachuk said, QProcess::startDetached will inherit parent handles to children: // qprocess_win.cpp Line 954
QProcess::CreateProcessArguments cpargs = {
nullptr, reinterpret_cast<wchar_t *>(const_cast<ushort *>(args.utf16())),
nullptr, nullptr, true, dwCreationFlags, envPtr,
workingDirectory.isEmpty()
? nullptr : reinterpret_cast<const wchar_t *>(workingDirectory.utf16()),
&startupInfo, &pinfo
};
success = callCreateProcess(&cpargs); However @ihor-drachuk's testcase still run ok on my windows 11. |
This commit closes an issue #259:
If application starts another app and then exits (leaving second app
running), listening socket created in first app is still alive (even
after app exit), but this socket isn't used by anyone and even
prevents to start listening again on the same port.