# Fix LSP spawning by resetting exception ports in child processes \(\#40716\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/8315fde1ff40dfc20241f51204099ef24cab29ee)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 8315fde1ff40dfc20241f51204099ef24cab29ee

Requested commit: 8315fde1ff40dfc20241f51204099ef24cab29ee

Commit: 8315fde1ff40dfc20241f51204099ef24cab29ee

Tree: 7464708beb5720454a0d84317d9d98db602cd350

Author: Rémi Kalbe

Committer: GitHub

## Message

```
Fix LSP spawning by resetting exception ports in child processes (#40716)

## Summary

Fixes #36754

This PR fixes an issue where LSPs fail to spawn after the crash handler
is initialized.

## Problem

After PR #35263 added minidump crash reporting, some users experienced
LSP spawn failures. The issue manifests as:
- LSPs fail to spawn with no clear error messages
- The problem only occurs after crash handler initialization
- LSPs work when a debugger is attached, revealing a timing issue

### Root Cause

The crash handler installs Mach exception ports for minidump generation.
Due to a timing issue, child processes inherit these exception ports
before they're fully stabilized, which can block child process spawning.

## Solution

Reset exception ports in child processes using the `pre_exec()` hook,
which runs after `fork()` but before `exec()`. This prevents children
from inheriting the parent's crash handler exception ports.

### Implementation

- Adds macOS-specific implementation of `new_smol_command()` that resets
exception ports before exec
- Calls `task_set_exception_ports` to reset all exception ports to
`MACH_PORT_NULL`
- Graceful error handling: logs warnings but doesn't fail process
spawning if port reset fails

Release Notes:

- Fixed LSPs failing to spawn on some macOS systems

---------

Co-authored-by: Julia Ryan <juliaryan3.14@gmail.com>
```

## Parents

- [fc8744068213741b8bf4508919af460b4eb59b66](https://git.cafe/gitcafe/zed/commit/fc8744068213741b8bf4508919af460b4eb59b66?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/8315fde1ff40dfc20241f51204099ef24cab29ee?format=markdown)
