diff --git a/external-providers/java-external-provider/pkg/java_external_provider/provider.go b/external-providers/java-external-provider/pkg/java_external_provider/provider.go index b5f27481..f028f0ea 100644 --- a/external-providers/java-external-provider/pkg/java_external_provider/provider.go +++ b/external-providers/java-external-provider/pkg/java_external_provider/provider.go @@ -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 { @@ -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) diff --git a/external-providers/java-external-provider/pkg/java_external_provider/service_client.go b/external-providers/java-external-provider/pkg/java_external_provider/service_client.go index df9fee77..edd84a63 100644 --- a/external-providers/java-external-provider/pkg/java_external_provider/service_client.go +++ b/external-providers/java-external-provider/pkg/java_external_provider/service_client.go @@ -229,7 +229,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) {