refactor: fix macOS SIGABRT crash in lsp-download-install by replacing url-copy-file thread with make-process (curl)#5022
Open
roryhow wants to merge 2 commits intoemacs-lsp:masterfrom
Conversation
…download-install url-copy-file calls url-retrieve-synchronously, which on macOS drives the NS/Cocoa event loop via ns_select_1. That function asserts it is running on the main thread and aborts (EXC_CRASH / SIGABRT) when called from a background Emacs Lisp thread spawned by make-thread. Replace the make-thread + url-copy-file approach with make-process (curl) and a :sentinel callback. The sentinel fires on the main thread via the normal event loop, which is safe on all platforms. This matches the pattern used by plz.el, request.el, and package.el. Decompression remains in a make-thread as it is CPU-bound and does not touch the event loop. Add ERT tests covering: missing curl, correct process invocation, successful download, curl failure, and all decompress variants.
jcs090218
approved these changes
Apr 18, 2026
Member
jcs090218
left a comment
There was a problem hiding this comment.
I haven't done the manual test yet, but the code looks good to me!
Can someone give it a try on macOS? 🤔
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.
Problem
On macOS (Emacs 30+, ARM), installing a language server via
lsp-install-servercrashes Emacs withEXC_CRASH (SIGABRT). The crash is a thread-safety violation in the NS/Cocoa backend.lsp-download-installwraps the download inmake-thread. Inside that thread,url-copy-filecallsurl-retrieve-synchronously, which pumps the macOS event loop vians_select_1. That function contains an assertion that it only runs on the main thread — violated here, causingemacs_abort.The crash stack:
This is also the root cause of the softer error seen on Linux in #3006 ("Attempt to accept output from process ... locked to thread"), where the NS assertion doesn't fire but the thread-safety violation still produces a Lisp error.
Fix
Replace
url-copy-file(and themake-threadwrapping it) withmake-processrunningcurl, plus a:sentinelcallback. The sentinel fires on the main thread via the normal Emacs event loop — no thread-safety issues on any platform.This is the same pattern used by established Emacs HTTP libraries:
plz.el—make-process+:sentinelrequest.el—start-process+set-process-sentinelDecompression (
:gzip,:zip,:targz,:tarxz) remains in amake-thread— those steps usecall-processinternally and do not touch the NS event loop, so they are thread-safe.Changes
lsp-mode.el: add privatelsp--download-filehelper; refactorlsp-download-installto use ittest/lsp-mode-test.el: add 5 ERT tests covering missing curl, correct invocation, success, failure, and all decompress variantsCHANGELOG.org: entry in UnreleasedNotes
curlis a hard requirement for the download path. It ships with macOS and is present on virtually all Linux systems. A clear error is raised if it is not found. Opinions or alternatives to this approach are welcome.