From c18e54189ce3ced76d95278a6deb96c38e50582a Mon Sep 17 00:00:00 2001 From: Jeff Hubbard Date: Wed, 27 Oct 2021 15:40:49 -0700 Subject: [PATCH] Adds a timeout context to the ssh waiter to prevent indefinite hanging --- pkg/liveshare/rpc.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/liveshare/rpc.go b/pkg/liveshare/rpc.go index bfd214c89..3645f85c0 100644 --- a/pkg/liveshare/rpc.go +++ b/pkg/liveshare/rpc.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "time" "github.com/opentracing/opentracing-go" "github.com/sourcegraph/jsonrpc2" @@ -32,7 +33,11 @@ func (r *rpcClient) do(ctx context.Context, method string, args, result interfac return fmt.Errorf("error dispatching %q call: %w", method, err) } - return waiter.Wait(ctx, result) + // timeout for waiter in case a connection cannot be made + waitCtx, cancel := context.WithTimeout(ctx, 2*time.Second) + defer cancel() + + return waiter.Wait(waitCtx, result) } type nullHandler struct{}