Skip to content

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

Closed

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"}.

Activity

  1. DanTup commented on Jan 7, 2021

    @DanTup
    ContributorAuthor

    Commenting out this call to exit does stop the error occurring. Perhaps connection.shutdown is closing the connection so exit can't be written?

    Screenshot 2021-01-07 at 15 32 53

  2. added
    bug
    on Jan 8, 2021
  3. added this to the milestone on Jan 8, 2021
  4. rgrunber commented on Aug 27, 2021

    @rgrunber

    I believe this is a duplicate of #726, which has been fixed for the 3.16.1 milestone. At least for me, the behaviour described (exit not sent) went hand in hand with the error reported here.

  5. dbaeumer commented on Aug 30, 2021

    @dbaeumer
    Member

    Yes, this got addressed but in the upcoming 3.17 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions