fix(upgrade): replace Bun.mmap with arrayBuffer on macOS to prevent SIGKILL#340
Merged
fix(upgrade): replace Bun.mmap with arrayBuffer on macOS to prevent SIGKILL#340
Conversation
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Trace
Other
Bug Fixes 🐛Api
Formatters
Setup
Upgrade
Other
Documentation 📚
Internal Changes 🔧Api
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 2681 passed | Total: 2681 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 3108 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 82.62% 82.62% —%
==========================================
Files 127 127 —
Lines 17880 17883 +3
Branches 0 0 —
==========================================
+ Hits 14772 14775 +3
- Misses 3108 3108 —
- Partials 0 0 —Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
…IGKILL Bun.mmap() always requests PROT_WRITE regardless of the `shared` flag. On macOS, AMFI code signing enforcement sends an uncatchable SIGKILL for ANY writable mapping (MAP_SHARED or MAP_PRIVATE) on code-signed Mach-O binaries — which all Bun-compiled binaries are. The previous fix (PR #339, { shared: false }) was insufficient because MAP_PRIVATE with PROT_WRITE is also rejected. Sentry telemetry confirmed: zero successful macOS upgrade traces from delta-enabled versions, while Linux worked fine. Use a platform check: on macOS, read the old binary into memory via Bun.file().arrayBuffer() (~100 MB heap, freed after patching). On Linux, keep the zero-heap Bun.mmap() path since ELF binaries have no such restriction.
10cfb5c to
d6a972a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
`Bun.mmap()` always requests `PROT_WRITE` in its implementation regardless of the `shared` flag. On macOS, AMFI code signing enforcement sends an uncatchable `SIGKILL` for any writable mapping (`MAP_SHARED` or `MAP_PRIVATE`) on code-signed Mach-O binaries — which all Bun-compiled binaries are.
PR #339's `{ shared: false }` (MAP_PRIVATE) fix was insufficient. Sentry telemetry confirmed: zero successful macOS upgrade traces from delta-enabled versions, while Linux worked fine.
Fix
Platform-conditional old file loading in `src/lib/bspatch.ts`:
Evidence