Skip to content

Commit

Permalink
🐛 CP # 746 - Adding ability for provider and service client to shutdo…
Browse files Browse the repository at this point in the history
…wn grac… (#748)

…efully (#746)

This will update and catch the context cancel to close the pipes for
stdin and stdout.

Signed-off-by: Shawn Hurley <[email protected]>
Co-authored-by: Shawn Hurley <[email protected]>
  • Loading branch information
eemcmullan and shawn-hurley authored Dec 11, 2024
1 parent 17a5d85 commit e064665
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
return nil, additionalBuiltinConfig, err
}

waitErrorChannel := make(chan error)
go func() {
err := cmd.Start()
if err != nil {
Expand All @@ -378,6 +379,23 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
log.Error(err, "unable to start lsp command")
return
}
// Here we need to wait for the command to finish or if the ctx is cancelled,
// To close the pipes.
select {
case err := <-waitErrorChannel:
if err != nil {
log.Error(err, "language server stopped with error")
}
log.V(5).Info("language server stopped")
case <-ctx.Done():
log.Info("language server context cancelled closing pipes")
stdin.Close()
stdout.Close()
}
}()
// This will close the go routine above when wait has completed.
go func() {
waitErrorChannel <- cmd.Wait()
}()
rpc := jsonrpc2.NewConn(jsonrpc2.NewHeaderStream(stdout, stdin), log)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ func (p *javaServiceClient) GetAllReferences(ctx context.Context, symbol protoco

func (p *javaServiceClient) Stop() {
p.cancelFunc()
p.cmd.Wait()
err := p.cmd.Wait()
if err != nil {
p.log.Info("stopping java provider", "error", err)
}
}

func (p *javaServiceClient) initialization(ctx context.Context) {
Expand Down

0 comments on commit e064665

Please sign in to comment.