Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta Para iniciantes
#64,742 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
76/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
go

Direção de pesquisa

Comece em tsc/internal/lsp/server.go, acompanhando o caminho da issue por handleExit, dispatchLoop e Run; depois, leia tsc/cmd/tsc/lsp.go, onde o erro se transforma no código de saída 1. Reproduza o problema com o repro.py fornecido, tanto com um documento aberto quanto sem nenhum documento aberto. O trabalho estará concluído quando um shutdown normal seguido de exit retornar o código 0, enquanto o comportamento de saída inesperada descrito na issue permanecer intacto.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

🔎 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

Linguagem predominante
Go
Estrelas
111k
Forks
16.4k
Merge médio
1d 11h
PRs com merge (30d)
148

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de microsoft/TypeScript

Todas as issues de microsoft/TypeScript

Issues semelhantes

Mais issues de Go

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.