Skip to content

[EventPipe] Fix reverse connection socket leaking to child processes. - #65365

Merged
hoyosjs merged 2 commits into
dotnet:mainfrom
hoyosjs:juhoyosa/fix-ep-hang
Feb 23, 2022
Merged

hoyosjs merged 2 commits into
dotnet:mainfrom
hoyosjs:juhoyosa/fix-ep-hang

Conversation

@hoyosjs

@hoyosjs hoyosjs commented Feb 15, 2022

Copy link
Copy Markdown
Member

Sockets were getting leaked upon accepting connections. This meant that child processes could cause fully terminated tracing sessions and other IPC connections alive, causing clients to wait for input indefinitely. This sets the CLOEXEC bits on the socket atomically upon accepting if the OS provides the capability, falling back to a best effort fcntl on systems like macOS and x866 Android emulators.

@hoyosjs
hoyosjs requested review from a team, lateralusX and wfurt February 15, 2022 08:48
@hoyosjs
hoyosjs requested a review from marek-safar as a code owner February 15, 2022 08:48
@ghost ghost added the area-Tracing-coreclr label Feb 15, 2022
@ghost ghost assigned hoyosjs Feb 15, 2022
@am11

am11 commented Feb 15, 2022

Copy link
Copy Markdown
Member

@hoyosjs, current approach is that callers of eventpipe's cmake script (in coreclr and mono) provide the introspection-driven definitions. Should accept4 check also live in the callers' configs?

@hoyosjs

hoyosjs commented Feb 15, 2022

Copy link
Copy Markdown
Member Author

@hoyosjs, current approach is that callers of eventpipe's cmake script (in coreclr and mono) provide the introspection-driven definitions. Should accept4 check also live in the callers' configs?

I am somewhat torn. src/coreclr, src/mono, and src/native/libs always do the checks + configure_file in the same configure.cmake file. I left it that way and have the shared configure file as this makes it easy to find where it is and in this case they are properly shared in between the two runtimes. I don't know if moving the HAVE_ACCEPT4 check to src/mono/cmake/configure.cmake and a similar one for CoreCLR or creating separate ones for event pipe + doing the configure in tree would help much with discovery. @janvorli @akoeplinger any words of idiomatic CMake advice here?

@janvorli

Copy link
Copy Markdown
Member

I would actually prefer having this local configure.cmake like @hoyosjs has done here and stop including the global configured header. It seems better to keep the detection close to the component that uses it. Unless I'm missing something, there is only HAVE_INTTYPES_H being used in the whole eventpipe stuff, so I'd copy the detection to the configure.cmake that was added here.

@hoyosjs

hoyosjs commented Feb 15, 2022

Copy link
Copy Markdown
Member Author

@janvorli I saw that too, but I couldn't find anything that checks and sets HAVE_INTTYPES_H, so I ignored for now as this is intended for servicing.

@janvorli

Copy link
Copy Markdown
Member

Ah, right, it is not checked for anywhere by cmake :-) It seems it is something that was inherited from autoconf.

@am11

am11 commented Feb 15, 2022

Copy link
Copy Markdown
Member

OK. One check requiring two new files, so I thought it can be pulled up in the existing config files.

Unless I'm missing something, there is only HAVE_INTTYPES_H being used in the whole eventpipe stuff

I was actually looking at FEATURE_ flags used extensively in eventpipe, which we define in coreclr and mono configs. Secondly, eventpipe is not self-dependent component at all, changing the order of headers (what is included before the ep_ header on consumer side) can break the compilation.

@hoyosjs
hoyosjs force-pushed the juhoyosa/fix-ep-hang branch from 905d04e to 67bd13f Compare February 16, 2022 05:11

@noahfalk noahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@lateralusX lateralusX left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the HAVE_INTTYPES_H can probably be removed, at least on the Mono side since we already include inttypes.h without guard in glib.h that will be included on all platforms, but that change could be done in a separate PR in main after this has merged.

Mono already include most of similar HAVE_XXX checks in https://github.com/dotnet/runtime/blob/main/src/mono/cmake/config.h.in and https://github.com/dotnet/runtime/blob/main/src/mono/cmake/configure.cmake, but if we want to add a new shared EventPipe config header instead of putting this into the same place as we currently have all other platform checks, I'm fine with that too.

@hoyosjs
hoyosjs merged commit ce19375 into dotnet:main Feb 23, 2022
@hoyosjs
hoyosjs deleted the juhoyosa/fix-ep-hang branch February 23, 2022 08:21
@hoyosjs

hoyosjs commented Feb 23, 2022

Copy link
Copy Markdown
Member Author

/backport to release/6.0

@github-actions

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown
Contributor

@hoyosjs backporting to release/6.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: [EventPipe] Fix reverse connection socket leaking to child processes.
.git/rebase-apply/patch:104: space before tab in indent.
    	client_socket = accept4 (s, address, address_len, SOCK_CLOEXEC);
.git/rebase-apply/patch:106: space before tab in indent.
    	client_socket = accept (s, address, address_len);
warning: 2 lines add whitespace errors.
Using index info to reconstruct a base tree...
M	src/coreclr/CMakeLists.txt
M	src/coreclr/debug/debug-pal/CMakeLists.txt
M	src/coreclr/vm/eventing/eventpipe/CMakeLists.txt
M	src/mono/mono/eventpipe/CMakeLists.txt
M	src/native/eventpipe/ds-ipc-pal-socket.c
Falling back to patching base and 3-way merge...
Auto-merging src/native/eventpipe/ds-ipc-pal-socket.c
Auto-merging src/mono/mono/eventpipe/CMakeLists.txt
CONFLICT (content): Merge conflict in src/mono/mono/eventpipe/CMakeLists.txt
Auto-merging src/coreclr/vm/eventing/eventpipe/CMakeLists.txt
Auto-merging src/coreclr/debug/debug-pal/CMakeLists.txt
Auto-merging src/coreclr/CMakeLists.txt
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 [EventPipe] Fix reverse connection socket leaking to child processes.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

hoyosjs added a commit to hoyosjs/runtime that referenced this pull request Feb 23, 2022
…ld processes.

Sockets were getting leaked upon accepting connections. This meant that child processes could cause
fully terminated tracing sessions and other IPC connections alive, causing clients to wait for input
indefinitely. This sets the CLOEXEC bits on the socket atomically upon accepting if the OS provides
the capability, falling back to a best effort fcntl on systems like macOS and x866 Android emulators.

Port of dotnet#65365 to release/6.0.
carlossanlop pushed a commit that referenced this pull request Mar 8, 2022
…ld processes. (#65768)

* [release/6.0][EventPipe] Fix reverse connection socket leaking to child processes.

Sockets were getting leaked upon accepting connections. This meant that child processes could cause
fully terminated tracing sessions and other IPC connections alive, causing clients to wait for input
indefinitely. This sets the CLOEXEC bits on the socket atomically upon accepting if the OS provides
the capability, falling back to a best effort fcntl on systems like macOS and x866 Android emulators.

Port of #65365 to release/6.0.

* Include well know cmake paths
@ghost ghost locked as resolved and limited conversation to collaborators Mar 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants