X Tutup
Skip to content

Commit c18e541

Browse files
committed
Adds a timeout context to the ssh waiter to prevent indefinite hanging
1 parent d794a92 commit c18e541

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/liveshare/rpc.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io"
7+
"time"
78

89
"github.com/opentracing/opentracing-go"
910
"github.com/sourcegraph/jsonrpc2"
@@ -32,7 +33,11 @@ func (r *rpcClient) do(ctx context.Context, method string, args, result interfac
3233
return fmt.Errorf("error dispatching %q call: %w", method, err)
3334
}
3435

35-
return waiter.Wait(ctx, result)
36+
// timeout for waiter in case a connection cannot be made
37+
waitCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
38+
defer cancel()
39+
40+
return waiter.Wait(waitCtx, result)
3641
}
3742

3843
type nullHandler struct{}

0 commit comments

Comments
 (0)
X Tutup