Skip to content

Fix #159: LanguageServer.Shutdown hangs on flush #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ protected override void Initialize()
this.SetRequestHandler(DebugAdapterMessages.EvaluateRequest.Type, this.HandleEvaluateRequest);
}

protected override void Shutdown()
protected override async Task Shutdown()
{
// Make sure remaining output is flushed before exiting
this.outputDebouncer.Flush().Wait();
await this.outputDebouncer.Flush();

Logger.Write(LogLevel.Normal, "Language service is shutting down...");

Expand Down
24 changes: 11 additions & 13 deletions src/PowerShellEditorServices.Protocol/Server/LanguageServerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ protected override Task OnStart()
return Task.FromResult(true);
}

protected override Task OnStop()
protected override async Task OnStop()
{
this.Shutdown();

return Task.FromResult(true);
await this.Shutdown();
}

/// <summary>
Expand All @@ -49,37 +47,37 @@ protected override Task OnStop()

/// <summary>
/// Can be overridden by the subclass to provide shutdown
/// logic before the server exits.
/// logic before the server exits. Subclasses do not need
/// to invoke or return the value of the base implementation.
/// </summary>
protected virtual void Shutdown()
protected virtual Task Shutdown()
{
// No default implementation yet.
return Task.FromResult(true);
}

private Task HandleShutdownRequest(
private async Task HandleShutdownRequest(
object shutdownParams,
RequestContext<object> requestContext)
{
// Allow the implementor to shut down gracefully
this.Shutdown();
await this.Shutdown();

return requestContext.SendResult(new object());
await requestContext.SendResult(new object());
}

private Task HandleExitNotification(
private async Task HandleExitNotification(
object exitParams,
EventContext eventContext)
{
// Stop the server channel
this.Stop();
await this.Stop();

// Notify any waiter that the server has exited
if (this.serverExitedTask != null)
{
this.serverExitedTask.SetResult(true);
}

return Task.FromResult(true);
}
}
}
Expand Down