Skip to content

Commit e064665

Browse files
🐛 CP # 746 - Adding ability for provider and service client to shutdown 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]>
1 parent 17a5d85 commit e064665

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

external-providers/java-external-provider/pkg/java_external_provider/provider.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
370370
return nil, additionalBuiltinConfig, err
371371
}
372372

373+
waitErrorChannel := make(chan error)
373374
go func() {
374375
err := cmd.Start()
375376
if err != nil {
@@ -378,6 +379,23 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
378379
log.Error(err, "unable to start lsp command")
379380
return
380381
}
382+
// Here we need to wait for the command to finish or if the ctx is cancelled,
383+
// To close the pipes.
384+
select {
385+
case err := <-waitErrorChannel:
386+
if err != nil {
387+
log.Error(err, "language server stopped with error")
388+
}
389+
log.V(5).Info("language server stopped")
390+
case <-ctx.Done():
391+
log.Info("language server context cancelled closing pipes")
392+
stdin.Close()
393+
stdout.Close()
394+
}
395+
}()
396+
// This will close the go routine above when wait has completed.
397+
go func() {
398+
waitErrorChannel <- cmd.Wait()
381399
}()
382400
rpc := jsonrpc2.NewConn(jsonrpc2.NewHeaderStream(stdout, stdin), log)
383401

external-providers/java-external-provider/pkg/java_external_provider/service_client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ func (p *javaServiceClient) GetAllReferences(ctx context.Context, symbol protoco
225225

226226
func (p *javaServiceClient) Stop() {
227227
p.cancelFunc()
228-
p.cmd.Wait()
228+
err := p.cmd.Wait()
229+
if err != nil {
230+
p.log.Info("stopping java provider", "error", err)
231+
}
229232
}
230233

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

0 commit comments

Comments
 (0)