fix(lsp): prevent socket deadlock on large files with incremental sync#16538
fix(lsp): prevent socket deadlock on large files with incremental sync#16538JayZenith wants to merge 1 commit intoanomalyco:devfrom
Conversation
Track open file content to compute line-level diffs for didChange, avoiding full-document resends on every edit. Fire all notifications without awaiting so writes stream to the LSP server without blocking on a saturated socket buffer.
|
The following comment was made by an LLM, it may be inaccurate: Found 1 potentially related PR: #16114: fix(lsp): timeout write to prevent hang when LSP server stdin is full This PR appears to be addressing a related issue (socket buffer saturation causing hangs) but uses a different approach (write timeouts). Since PR #16538 (the current PR) closes issue #16115 and provides a more comprehensive fix with incremental diffs and fire-and-forget notifications, #16114 may be an earlier attempt or alternative solution to the same underlying problem. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
@thdxr found this while working on sglang, took a while to track down but the socket profiling made it pretty clear what was happening. lmk if you have any questions. |
Issue for this PR
Closes #16115
Type of change
What does this PR do?
Patching large Python files (e.g. server_args.py in sglang, ~255KB) causes opencode to hang indefinitely on "Preparing patch...".
textDocument/didOpen and textDocument/didChange both sent the full file content over a Unix domain socket. At 255KB this overflows the ~213KB kernel socket buffer. When pyright is CPU-saturated on its initial project scan it can't drain the socket fast enough, both sides stall waiting on each other. Deadlock.
Two changes:
How did you verify your code works?
Profiled both the official nightlyand this fix simultaneously using ss -xp to observe Unix socket buffer states.
Official nightly on server_args.py inside sglang:
Recv-Q: 219,461 -> pyright's buffer, not draining
Send-Q: 224,000 -> opencode blocked on write, pyright at 108% CPU.
This fix under the same conditions:
Recv-Q: 561 -> draining normally
Send-Q: 0 ->opencode not blocked
Two back-to-back patches on server_args.py completed without hanging.
Screenshots / recordings
N/A
Checklist