Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 13, 2026

Alpine Linux builds fail because musl libc headers don't define CLOSE_RANGE_CLOEXEC, despite the syscall being available:

error: 'CLOSE_RANGE_CLOEXEC' was not declared in this scope
  135 |   if (syscall(SYS_close_range, 3, ~0U, CLOSE_RANGE_CLOEXEC) == 0) {

Changes

  • src/unix/pty.cc: Modified the conditional compilation to check for both SYS_close_range and CLOSE_RANGE_CLOEXEC before using the close_range() syscall
    #if defined(SYS_close_range) && defined(CLOSE_RANGE_CLOEXEC)

When CLOSE_RANGE_CLOEXEC is not defined (as on Alpine/musl), the code gracefully skips the close_range() optimization and falls back to the existing loop-based approach for setting close-on-exec flags.

Testing

  • ✅ Code compiles successfully on Ubuntu 24.04
  • ✅ All 20 tests pass
  • ✅ Linting passes without errors

The changes are minimal and surgical, ensuring compatibility with Alpine Linux while maintaining the optimization on systems where it's available.

Original prompt

This section details on the original issue you should resolve

<issue_title>CLOEXEC does not work on Alpine</issue_title>
<issue_description>In the VS Code repo, when I bump node-pty, the Alpine build reports the following error

2026-01-13T21:31:14.7685867Z npm error ../src/unix/pty.cc: In function 'void pty_close_inherited_fds()':
2026-01-13T21:31:14.7686207Z npm error ../src/unix/pty.cc:135:40: error: 'CLOSE_RANGE_CLOEXEC' was not declared in this scope
2026-01-13T21:31:14.7686533Z npm error   135 |   if (syscall(SYS_close_range, 3, ~0U, CLOSE_RANGE_CLOEXEC) == 0) {
2026-01-13T21:31:14.7686816Z npm error       |                                        ^~~~~~~~~~~~~~~~~~~
2026-01-13T21:31:14.7687112Z npm error make: *** [pty.target.mk:115: Release/obj.target/pty/src/unix/pty.o] Error 1
2026-01-13T21:31:14.7687392Z npm error gyp ERR! build error 
2026-01-13T21:31:14.7687660Z npm error gyp ERR! stack Error: `make` failed with exit code: 2

Look in pty.cc and see whether we have to use a different constant or implementation for Alpine.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix CLOEXEC issue in Alpine build for node-pty Define CLOSE_RANGE_CLOEXEC for musl libc compatibility Jan 13, 2026
Copilot AI requested a review from rzhao271 January 13, 2026 22:35
@rzhao271
Copy link
Contributor

@copilot do not declare a value for the constant. Instead, add to the #if so that if the constant is not defined, skip that block.

Copy link
Contributor Author

Copilot AI commented Jan 13, 2026

@copilot do not declare a value for the constant. Instead, add to the #if so that if the constant is not defined, skip that block.

Changed the conditional to check for both SYS_close_range and CLOSE_RANGE_CLOEXEC. When the constant is not defined, the close_range() block is skipped and the fallback loop is used instead. (fd2eea6)

Copilot AI changed the title Define CLOSE_RANGE_CLOEXEC for musl libc compatibility Fix CLOSE_RANGE_CLOEXEC build error on Alpine Jan 13, 2026
@rzhao271 rzhao271 marked this pull request as ready for review January 13, 2026 23:03
@rzhao271 rzhao271 added this to the January 2026 milestone Jan 13, 2026
@rzhao271 rzhao271 requested a review from Tyriar January 13, 2026 23:03
@rzhao271 rzhao271 enabled auto-merge (squash) January 13, 2026 23:04
@rzhao271 rzhao271 merged commit ac22bd8 into main Jan 13, 2026
9 checks passed
@rzhao271 rzhao271 deleted the copilot/fix-cloexec-error-alpine branch January 13, 2026 23:34
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.

CLOEXEC does not work on Alpine

3 participants