Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#64,742 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go

Línea de trabajo

Empieza en tsc/internal/lsp/server.go y sigue el recorrido del issue por handleExit, dispatchLoop y Run; después, lee tsc/cmd/tsc/lsp.go, donde el error se convierte en el código de salida 1. Reproduce el problema con el repro.py proporcionado, tanto con un documento abierto como sin él. Se considera terminado cuando un shutdown correcto seguido de exit devuelve el código 0 y se mantiene el comportamiento ante una salida inesperada descrito en el issue.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

🔎 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

Lenguaje dominante
Go
Estrellas
111k
Forks
16.4k
Merge medio
1 d 11 h
PR fusionados (30 d)
148

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/TypeScript

Todos los issues de microsoft/TypeScript

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.