Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`

Aperta Adatta ai principianti
#64,742 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Inizia da tsc/internal/lsp/server.go, seguendo il percorso dell’issue attraverso handleExit, dispatchLoop e Run; poi leggi tsc/cmd/tsc/lsp.go, dove l’errore diventa il codice di uscita 1. Riproduci il problema con il repro.py fornito, sia con un documento aperto sia senza. Il lavoro è completo quando un shutdown regolare seguito da exit restituisce il codice 0, mentre il comportamento di uscita imprevista descritto nell’issue rimane invariato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🔎 Search Terms

tsc --lsp exit code 1, shutdown exit, context canceled, handleExit io.EOF, LSP exit notification

🕗 Version & Regression Information
  • I was unable to test this on prior versions because --lsp is new in TypeScript 7: seen with typescript 7.0.2 (tsc --lsp --stdio), macOS arm64. I have not run the nightly; the code path below is unchanged on main at aa81492.
⏯ Playground Link

No response (language server, not type checking)

💻 Code

Save as repro.py and run python3 repro.py in any directory. It initializes tsc --lsp --stdio, sends shutdown, then exit, and prints the exit code (given a URI, it opens a document first; no argument opens nothing).

# python3 repro.py [URI to open], in a directory with a tsconfig.json
import json, os, subprocess, sys

p = subprocess.Popen(["tsc", "--lsp", "--stdio"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)

def send(msg):
    body = json.dumps({"jsonrpc": "2.0", **msg}).encode()
    p.stdin.write(b"Content-Length: %d\r\n\r\n%s" % (len(body), body))
    p.stdin.flush()

def reply(id):
    while True:
        length = None
        while (line := p.stdout.readline()) not in (b"\r\n", b""):
            if line.lower().startswith(b"content-length:"):
                length = int(line.split(b":")[1])
        if length is None:
            return None  # the server is gone
        msg = json.loads(p.stdout.read(length))
        if "method" in msg and "id" in msg:  # a request from the server
            send({"id": msg["id"], "result": None})
        elif msg.get("id") == id:
            return msg

root = "file://" + os.getcwd()
send({"id": 1, "method": "initialize", "params": {"processId": os.getpid(), "rootUri": root, "capabilities": {}}})
reply(1)
send({"method": "initialized", "params": {}})
if len(sys.argv) > 1:
    doc = {"uri": sys.argv[1], "languageId": "typescript", "version": 0, "text": "const x = 1;\n"}
    send({"method": "textDocument/didOpen", "params": {"textDocument": doc}})
send({"id": 2, "method": "shutdown"})
if reply(2) is not None:
    send({"method": "exit"})
print("exit code:", p.wait())
🙁 Actual behavior
$ python3 repro.py
context canceled
exit code: 1

The server exits with code 1 after a clean shutdown and exit. Neovim reports any non-zero exit, so every :lsp restart shows "Client tsc quit with exit code 1 and signal 0. Check log for errors".

Reading main at aa81492, the path looks like this:

  • handleExit returns io.EOF.
  • dispatchLoop answers that with lspExit(nil), which cancels the loop's context.
  • Its next s.requestQueue.Get(ctx) then returns context.Canceled, and the loop returns that.
  • Run passes it on, since it isn't io.EOF and the group's context is done.
  • cmd/tsc/lsp.go prints it and returns 1.
🙂 Expected behavior

Exit code 0: the LSP spec asks for 0 when shutdown came before exit, and 1 otherwise.

Additional information about the issue

No response

Lingua principale
Go
Stelle
111k
Fork
16.4k
Merge medio
1g 16h
PR unite (30g)
154

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/TypeScript

Tutte le issue di microsoft/TypeScript

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.