Skip to content

Avoid calls to (*os.File).Fd() when calling ioctl - #215

Merged
creack merged 3 commits into
creack:masterfrom
WeidiDeng:unsafe-pointer
Jun 1, 2026
Merged

creack merged 3 commits into
creack:masterfrom
WeidiDeng:unsafe-pointer

Conversation

@WeidiDeng

Copy link
Copy Markdown
Contributor

Like #214 , but use unsafe.Pointer as a parameter to avoid the use of reflect.

@WeidiDeng

Copy link
Copy Markdown
Contributor Author

@creack Do you have time to review this pr? I'd like to use the non blocking operation without manually calling syscall.SetNonblock.

@creack

creack commented Mar 12, 2026

Copy link
Copy Markdown
Owner

Will try to take a look over the weekend but may be the weekend after that.

@WeidiDeng

Copy link
Copy Markdown
Contributor Author

@creack Do you have time to review this pr?

@WeidiDeng

Copy link
Copy Markdown
Contributor Author

I think //go:uintptrescapes directive might need very few changes. Will test soon.

@creack

creack commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Thanks @WeidiDeng — really appreciate you sticking with this and following up on the earlier rounds (#214, the //go:uintptrescapes experiment).

The unsafe.Pointer-through-the-stack approach is the right way to satisfy unsafe.Pointer rule (4): the uintptr(ptr) conversion only happens inside the syscall.Syscall argument list, which is what keeps the referenced object alive across the call. That closes a latent GC hazard that's been in the codebase since well before #167.

Merging now. Will hold tagging/release until I've also added a stress test that exercises the SyscallConn().Control() + concurrent close/fork pattern that motivated the original #177 revert — want a more reproducible guard than -count=100. If anyone hits issues against master, please open a follow-up issue.

@creack
creack merged commit 9246436 into creack:master Jun 1, 2026
5 checks passed
Amitgb14 added a commit to Amitgb14/conch that referenced this pull request Oct 18, 2026
CI on Linux failed TestAutopilotMergeGatesTheMergedCommit: it waited for
the check's terminal to end and then read the verdict, which the server
records just after — the output is read before the end is announced, and
acted on in the background since the last fix. Linux was quick enough to
read first. The test now waits for the pass itself.

TestAutopilotCheckRuns had the same kind of gap, found by holding the
verdict back on purpose: its second start asks for a re-check once the
first ends, and that re-check's pass could replace the one the test reads.
The re-check has a test of its own, so this one clears it.

Both pass with the verdict held back 300ms, five runs in a row without,
and on one CPU. The other CI failure, TestAutopilotRequireTests's
"fork/exec ... operation not permitted", is the pty flake (creack/pty#215)
the unmerged conch/fix-creator-flake work is about, not this branch's.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Amitgb14 added a commit to Amitgb14/conch that referenced this pull request Oct 18, 2026
TestCreatorEveryWayFromAfar failed in CI now and then with "fork/exec …:
operation not permitted". creack/pty v1.1.20–v1.1.24 turned the pointer
for TIOCGPTN into a uintptr before the call making the system call, so a
GC shrinking the goroutine's stack in between had the kernel write the
pty's number into the old stack: Open read 0, opened /dev/pts/0 — another
pane's terminal — and TIOCSCTTY failed with EPERM.

The fix (creack/pty#215) is merged upstream but unreleased, so go.mod pins
the master pseudo-version. TestPtyOpenNamesItsOwnTerminal (Linux) opens
ptys under GC pressure and checks each tty is the master's own: on
v1.1.24 it fails within a run, on the pinned version 0 wrong in ~110k
opens.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
tobiabidoye added a commit to tobiabidoye/etcd that referenced this pull request Oct 19, 2026
v1.1.24 (bumped in etcd-io#22272) causes 'fork/exec: operation not permitted'
in e2e tests run under Prow. The bug was introduced upstream in v1.1.20
and the fix (creack/pty#215) is not yet in a release. See
creack/pty#196.

Fixes etcd-io#22610

Signed-off-by: Tobi Abidoye <tobiabidoye14@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants