Skip to content
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

Pass WSA_FLAG_NO_HANDLE_INHERIT flag to the WSASocketA() to avoid handle leaking on the Windows in case of using CreateProcess() on the server #18060

Merged
merged 12 commits into from Apr 29, 2019

Conversation

frazenshtein
Copy link
Contributor

handle leaking on the Windows in case of using CreateProcess() on the server
@thelinuxfoundation
Copy link

Thank you for your pull request. Before we can look at your contribution, we need to ensure all contributors are covered by a Contributor License Agreement.

After the following items are addressed, please respond with a new comment here, and the automated system will re-verify.

Regards,
CLA GitHub bot

@frazenshtein frazenshtein changed the title Pass WSA_FLAG_NO_HANDLE_INHERIT flags to the WSASocketA() to avoid handle leaking on the Windows in case of using CreateProcess() on the server Pass WSA_FLAG_NO_HANDLE_INHERIT flag to the WSASocketA() to avoid handle leaking on the Windows in case of using CreateProcess() on the server Feb 14, 2019
@yang-g
Copy link
Member

yang-g commented Feb 20, 2019

Please sign cla.

@jtattermusch
Copy link
Contributor

@frazenshtein is this PR an attempt to resolve #17704?
Have you been able to confirm that it fixes the problem?

Check WSA_FLAG_NO_HANDLE_INHERIT is supported.
@jtattermusch
Copy link
Contributor

@nicolasnoble opinions?

@AspirinSJL AspirinSJL added the release notes: no Indicates if PR should not be in release notes label Feb 21, 2019
@apolcyn
Copy link
Contributor

apolcyn commented Feb 28, 2019

Seeing this error in the linux artifact build:

[CXX]     Compiling src/core/lib/gpr/wrap_memcpy.cc
[CXX]     Compiling src/core/lib/gprpp/fork.cc
[CXX]     Compiling src/core/lib/gprpp/thd_posix.cc
[CXX]     Compiling src/core/lib/gprpp/thd_windows.cc
[CXX]     Compiling src/core/lib/profiling/basic_timers.cc
[AR]      Creating /tmp/libs/opt/libaddress_sorting.a
[CXX]     Compiling src/core/lib/profiling/stap_timers.cc
[AR]      Creating /tmp/libs/opt/libz.a
[AR]      Creating /tmp/libs/opt/libares.a
src/core/lib/iomgr/socket_windows.cc: In function 'void grpc_wsa_socket_flags_init()':
src/core/lib/iomgr/socket_windows.cc:193:77: error: passing NULL to non-pointer argument 5 of 'SOCKET WSASocketW(int, int, int, LPWSAPROTOCOL_INFOW, GROUP, DWORD)' [-Werror=conversion-null]
                           grpc_wsa_socket_flags | WSA_FLAG_NO_HANDLE_INHERIT);

@apolcyn
Copy link
Contributor

apolcyn commented Feb 28, 2019

is the header that contains the new socket option also available to mingw? That build failure is a mingw issue

@apolcyn
Copy link
Contributor

apolcyn commented Feb 28, 2019

I'm also wondering has this been verified to fix the issue. A test would be best but barring that it would be good to know that this has been manually verified

@jtattermusch
Copy link
Contributor

@frazenshtein, are you planning to address review feedback?

@frazenshtein
Copy link
Contributor Author

frazenshtein commented Mar 11, 2019

@frazenshtein, are you planning to address review feedback?

Yes, I will try to take into account the comments in the nearest future. I have some difficulties with the allocation of free time.

@frazenshtein
Copy link
Contributor Author

frazenshtein commented Mar 12, 2019

Seeing this error in the linux artifact build:

Yes, I really mixed up NULL and 0. Fixed.

is the header that contains the new socket option also available to mingw? That build failure is a mingw issue

Haven't found this one. Looks strange, because we have added #ifndef to the src/core/lib/iomgr/socket_windows.h Can you provide an error message or a link and keywords to grep?

let's turn this into a function rather than have everyone reference the global directly

Fixed. However, I'm happy to rename it to your liking. I didn't find a good example in the code, so it turned out a bit long.

I'm also wondering has this been verified to fix the issue. A test would be best but barring that it would be good to know that this has been manually verified

I was unable to reproduce the problem from the #17704 issue. If the author provides a minimal example it will be easier.
UPD: I have used cpp instead of c#, btw

@jtattermusch
Copy link
Contributor

jtattermusch commented Mar 14, 2019

I triggered an adhoc package build (the nugets) to be able to verify if this patch fixes #17704
https://sponge.corp.google.com/target?id=1c772a91-2b04-42ce-8d55-31a2a2990574&target=grpc/core/experimental/grpc_build_artifacts_multiplatform
I'll later post the link to the pre-built nugets.

@jtattermusch
Copy link
Contributor

According to #17704 (comment) this would fix #17704 if merged.

@jtattermusch
Copy link
Contributor

jtattermusch commented Apr 10, 2019

Do we want to use the default flags for resolver_component_test.cc too?

SOCKET s = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, nullptr, 0,

Copy link
Contributor

@jtattermusch jtattermusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for general sanity and we also have a confirmation that this fixes #17704.

@apolcyn besides what I mentioned in #18060 (comment), I'm mostly happy with the code in this PR, do you want to give it a quick pass and merge if it looks good?

@frazenshtein
Copy link
Contributor Author

Could you please make clear for me is something expected from my side?

@jtattermusch
Copy link
Contributor

jtattermusch commented Apr 29, 2019

I believe we need need to use grpc_get_default_wsa_socket_flags() here:

SOCKET s = WSASocket(af, type, protocol, nullptr, 0, WSA_FLAG_OVERLAPPED);

and here

WSA_FLAG_OVERLAPPED);

Update: ignore my comment.

@jtattermusch
Copy link
Contributor

@apolcyn I believe this is good to do, can you give owners approval so we can merge?

Copy link
Contributor

@apolcyn apolcyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, sorry for the delay

@jtattermusch jtattermusch merged commit 7820b44 into grpc:master Apr 29, 2019
@jtattermusch jtattermusch added release notes: yes Indicates if PR needs to be in release notes and removed release notes: no Indicates if PR should not be in release notes labels May 15, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jul 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang/core platform/Windows release notes: yes Indicates if PR needs to be in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants