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
os: make use of pidfd for linux #62654
Comments
Change https://go.dev/cl/528436 mentions this issue: |
I don't think there is an API change here (before optional item 7) so taking this out of the proposal process. CC @golang/runtime |
@ianlancetaylor can you please elaborate? Is this about FindProcess returning ErrProcessGone, or something else? If this is about FindProcess returning an error, as I pointed out in 4 above, this is entirely optional. We can make it succeed every time. |
What I mean is that we only need a proposal for an API change or a significant functionality change. This issue doesn't seem to be either, so we should treat it as an ordinary feature request issue, rather than running it through the proposal process. I hope that makes sense. Thanks. |
Thanks for the explanation, makes sense.I will keep working on implementation. |
Change https://go.dev/cl/528438 mentions this issue: |
Change https://go.dev/cl/528798 mentions this issue: |
I'm a bit unhappy w/ #4: ErrProcessGone could happen on any OS. Just practically only happens on Linux for now. So, developers always need to be prepared for this. |
@golang/runtime could you please take a look at this proposal as well as CLs implementing it? I would appreciate any feedback. |
Hi @kolyshkin, Sorry for the delay. I took a look at your CLs. I'm leaving some feedback here since it is about potential API changes.
|
@prattmic thanks for review comments, I updated the code based on your suggestions (except for the item 3, see below). In the process, I found a bug in my older PidFD implementation (see https://go.dev/cl/542698 for the fix). The series is now ready for (re-)review, I'd be grateful about any feedback. As for using GODEBUG, I feel the overall change is major and might break some setups (in particular, new syscalls are used, which might be blocked on some older systems, and the runtime workarounds may be too complex (see e.g. What do you think? CC @golang/runtime |
I agree, this seems reasonable. |
CL 520266 added pidfd_send_signal linux syscall numbers to the syscall package for the sake of a unit test. As pidfd_send_signal will be used from the os package, let's revert the changes to syscall package, add the pidfd_send_signal syscall numbers and the implementation to internal/syscall/unix, and change the above test to use it. Updates #51246. For #62654. Change-Id: I862174c3c1a64baf1080792bdb3a1c1d1b417bb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/528436 Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
@prattmic Implemented as discussed; PTAL https://go.dev/cl/528438 |
Based on a discussion in #51246 (in particular, #51246 (comment)), this is a proposal to implement pidfd support for process methods in the os package -- StartProcess, FindProcess, Kill, Wait.
Reuse the
handle
field ofstruct Process
to keep pidfd. Since0
is a valid value, use^uintptr(0)
as a default value (if pidfd is not known).Instrument
syscall.StartProcess
os.StartProcess
to getpidfd
from the kernel and return it as ahandle
. The initial idea was to modifysyscall.StartProcess
as it returns ahandle
(which we're reusing for pidfd) but that would be a change is not backward-compatible and can result in leaking pidfd as callers are not expecting it.Use pidfdSendSignal from
(*process).Signal
, if handle is known and the syscall is available; fallback to old code usingsyscall.Kill
if syscall is not available (e.g. disabled by seccomp).Use
waitid(P_PIDFD, ...)
in Wait, if pidfd is set; fall back to old code if P_PIDFD is not supported.ErrProcessGone
, and modify the documentation accordingly (adding that it can returnErrProcessGone
on Linux).(*Process).Handle() uintptr
method to return process handle on Windows and pidfd on Linux. This might be useful for low-level operations that require handle/pidfd (e.g. pidfd_getfd on Linux), or to ensure that pidfd (rather than pid) is being used for kill/wait.The text was updated successfully, but these errors were encountered: