Skip to content

Fix Mach port leak in alt_clock_gettime on macOS#4840

Open
qingweizhang054 wants to merge 1 commit intozeromq:masterfrom
qingweizhang054:dev4
Open

Fix Mach port leak in alt_clock_gettime on macOS#4840
qingweizhang054 wants to merge 1 commit intozeromq:masterfrom
qingweizhang054:dev4

Conversation

@qingweizhang054
Copy link

@qingweizhang054 qingweizhang054 commented Feb 1, 2026

Description:

This PR fixes a Mach port resource leak in the macOS implementation of alt_clock_gettime.

On macOS versions prior to 10.12 (Sierra, released in 2016), clock_gettime is not available, libzmq falls back to alt_clock_gettime, which uses Mach APIs to retrieve timing information. The current implementation calls mach_host_self() to obtain a host port, but does not release the associated send right after use.

Since mach_host_self() returns a send right that must be explicitly deallocated, repeated calls to alt_clock_gettime in long-running processes can lead to Mach port leaks and eventual resource exhaustion.

This change ensures that the host port returned by mach_host_self() is properly released via mach_port_deallocate() after use. The fix is limited to the legacy macOS code path and does not affect platforms that use the native clock_gettime implementation.

Impact:

  • Prevents Mach port leaks on older macOS systems
  • Improves stability for long-running applications
  • No behavior change on modern macOS or other platforms

@qingweizhang054 qingweizhang054 changed the title add Fix Mach port leak in alt_clock_gettime for macOS Feb 1, 2026
@qingweizhang054 qingweizhang054 changed the title Fix Mach port leak in alt_clock_gettime for macOS Fix Mach port leak in alt_clock_gettime on macOS Feb 1, 2026
@qingweizhang054
Copy link
Author

Note: CI reports failures on the GitHub Actions macOS runner in
tests/test_zmq_poll_fd and tests/test_zmq_ppoll_fd, where sendto()
returns EHOSTUNREACH (errno 65).

I cannot reproduce this locally on macOS, and this PR does not modify any
networking-related code paths. This appears to be an environment-specific
issue on the macOS runner rather than a regression introduced by this
change.

Relevant CI output:

FAIL: tests/test_zmq_poll_fd
sendto(...) failed, errno = 65 (Host unreachable)

FAIL: tests/test_zmq_ppoll_fd
sendto(...) failed, errno = 65 (Host unreachable)

@qingweizhang054
Copy link
Author

qingweizhang054 commented Feb 1, 2026

This PR is ready for review when convenient.
It fixes a resource leak in the macOS timing fallback and is limited
to the legacy macOS code path.

Thanks for your time.
@bluca

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.

1 participant