Skip to content

Disposing the server causes "rejected promise not handled within 1 second: Error [ERR_STREAM_WRITE_AFTER_END]" #723

@DanTup

Description

@DanTup

Disposing the LSP client seems to trigger this error. I see it in the Dart server when we restart the server (eg. if you change something that requires changing the command line arguments), but I can also reproduce it in an integration test using the source repo/test server here.

'use strict';

import * as child_process from "child_process";
import * as path from 'path';
import * as lsclient from 'vscode-languageclient/node';

suite('Client integration', () => {

	const serverModule = path.join(__dirname, './servers/testServer.js');
	const documentSelector: lsclient.DocumentSelector = [{ scheme: 'lsptests', language: 'bat' }];
	const middleware = {};
	const clientOptions: lsclient.LanguageClientOptions = {
		documentSelector,
		synchronize: {},
		initializationOptions: {},
		middleware
	};

	test.only('Can dispose and re-create language server', async () => {
		while (true) {
			const process = child_process.spawn(`node`, [serverModule, '--stdio']);
			process.stderr.on("data", (data) => console.error(data.toString()));
			process.on("exit", () => console.log(`LSP Server quit!`));

			console.log(`Creating server`);
			const client = new lsclient.LanguageClient(
				'test svr',
				'Test Language Server',
				() => Promise.resolve({ reader: process.stdout, writer: process.stdin }),
				clientOptions,
			);

			console.log(`Starting server`);
			const disp = client.start();

			console.log(`Waiting for server to be ready`);
			await client.onReady();

			console.log(`Waiting a little while before disposing...`);
			await new Promise((resolve) => setTimeout(resolve, 1000));

			console.log(`Disposing server`);
			disp.dispose();

			await new Promise((resolve) => setTimeout(resolve, 1000));
			console.log(`...`);
		}
	}).timeout(99999);
});

Screenshot 2021-01-07 at 15 22 46

I'm not certain, but it seems like it might be when it tries to send {"jsonrpc":"2.0","method":"exit"}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions