Skip to contentSkip to conversation

New: Undocumented EAGAIN behavior for clone/pthread_create

Bug 219947 [email protected] 1 participant 6 messages Mar 28, 2025 – Mar 31, 2025 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

https://bugzilla.kernel.org/show_bug.cgi?id=219947

Bug ID: 219947
Summary: Undocumented EAGAIN behavior for clone/pthread_create
Product: Documentation
Version: unspecified
Hardware: All
OS: Linux
Status: NEW
Severity: normal
Priority: P3
Component: man-pages
Assignee: [email protected]
Reporter: [email protected]
Regression: No

Currently, when a clone() is called with CLONE_FS (as is the case with pthread_create), and concurrently in another thread, an execve() syscall is in progress, the clone() call may return early with an EAGAIN error.

I think the corresponding location in the kernel returning EAGAIN is in kernel/fork.c inside copy_fs.

The man pages currently only document cases of resource exhaustion (and a SCHED_DEADLINE case which most people won't care about) under EAGAIN, in which case aborting the process is reasonable, but in this case it can result in the process exiting before the execve() syscall finishes.
This is nonsensical as the thread calling clone() was about to be deleted anyway.

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.
#1 lore raw

[Bug 219947] Undocumented EAGAIN behavior for clone/pthread_create

https://bugzilla.kernel.org/show_bug.cgi?id=219947

Carlos O'Donell ([email protected]) changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |[email protected]

--- Comment #1 from Carlos O'Donell ([email protected]) ---
Error number EGAIN is the best error return code for this scenario, from among those that pthread_create() can return.

The in-progress execve() could fail, at which point pthread_create() called again would succeed.

It deserves documenting that pthread_create() could fail with EAGAIN if an in-progress execve() is making forward-progress ahead of the thread, but could fail, in which case the thread could be created later.

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.
#2 lore raw

[Bug 219947] Undocumented EAGAIN behavior for clone/pthread_create

In reply to [email protected]

https://bugzilla.kernel.org/show_bug.cgi?id=219947

--- Comment #2 from Carlos O'Donell ([email protected]) --- Example:

man/man3/pthread_create.3 +6 -0
index 22926990e..ecb08b8e2 100644
@@ -126,6 +126,12 @@ or the maximum number of PIDs,
 was reached (see
 .BR proc (5)).
 .TP
+.B EAGAIN
+An in-progress kernel operation is preventing the creation of the
+thread, e.g.
+.BR execve (2),
+but if such an operation fails, the thread creation can be retried.
+.TP
 .B EINVAL
 Invalid settings in
 .IR attr .

---

Note that I'm not saying that the kernel implementation is right or wrong. I think it's an open design question if you should block, or return EAGAIN. Each has pros and cons.

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.
#3 lore raw

[Bug 219947] Undocumented EAGAIN behavior for clone/pthread_create

In reply to [email protected]

https://bugzilla.kernel.org/show_bug.cgi?id=219947

Alejandro Colomar ([email protected]) changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |[email protected]

--- Comment #3 from Alejandro Colomar ([email protected]) --- (In reply to Carlos O'Donell from comment #2)

Quoted 21 lines

Example:

man/man3/pthread_create.3 +6 -1
index 22926990e..ecb08b8e2 100644
@@ -126,6 +126,12 @@ or the maximum number of PIDs,
 was reached (see
 .BR proc (5)).
 .TP
+.B EAGAIN
+An in-progress kernel operation is preventing the creation of the
+thread, e.g.
+.BR execve (2),
+but if such an operation fails, the thread creation can be retried.
+.TP
 .B EINVAL
 Invalid settings in
 .IR attr .
---
Quoted 3 lines

Note that I'm not saying that the kernel implementation is right or wrong. I think it's an open design question if you should block, or return EAGAIN. Each has pros and cons.

Would you mind sending the patch to the mailing list, with a commit message (i.e., full output of git-format-patch(1))?

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.
#4 lore raw

[Bug 219947] Undocumented EAGAIN behavior for clone/pthread_create

In reply to [email protected]

https://bugzilla.kernel.org/show_bug.cgi?id=219947

--- Comment #4 from Carlos O'Donell ([email protected]) --- (In reply to Alejandro Colomar from comment #3)

Quoted 2 lines

Would you mind sending the patch to the mailing list, with a commit message (i.e., full output of git-format-patch(1))?

I'd like to give Kramer the opportunity to review, and possibly post their own version, otherwise I'll post a patch next week.

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.
#5 lore raw

[Bug 219947] Undocumented EAGAIN behavior for clone/pthread_create

In reply to [email protected]

https://bugzilla.kernel.org/show_bug.cgi?id=219947

--- Comment #5 from L. Kramer ([email protected]) ---

Quoted 2 lines

I'd like to give Kramer the opportunity to review, and possibly post their own version, otherwise I'll post a patch next week.

Yeah I'm fine with the wording. Would it make sense to also add a similar note to the clone man page?

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.