Skip to content

Commit c8d1157

Browse files
committed
fix: use separate contexts for connserver launch
1 parent 246640a commit c8d1157

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

pkg/wsl/wsl.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,8 @@ func (conn *WslConn) OpenDomainSocketListener() error {
187187
}
188188

189189
func (conn *WslConn) StartConnServer() error {
190-
ctx, cancelFn := context.WithCancel(context.Background())
191-
conn.WithLock(func() {
192-
if conn.cancelFn != nil {
193-
conn.cancelFn()
194-
}
195-
conn.cancelFn = cancelFn
196-
})
190+
utilCtx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)
191+
defer cancelFn()
197192
var allowed bool
198193
conn.WithLock(func() {
199194
if conn.Status != Status_Connecting {
@@ -206,7 +201,7 @@ func (conn *WslConn) StartConnServer() error {
206201
return fmt.Errorf("cannot start conn server for %q when status is %q", conn.GetName(), conn.GetStatus())
207202
}
208203
client := conn.GetClient()
209-
wshPath := GetWshPath(ctx, client)
204+
wshPath := GetWshPath(utilCtx, client)
210205
rpcCtx := wshrpc.RpcContext{
211206
ClientType: wshrpc.ClientType_ConnServer,
212207
Conn: conn.GetName(),
@@ -216,7 +211,7 @@ func (conn *WslConn) StartConnServer() error {
216211
if err != nil {
217212
return fmt.Errorf("unable to create jwt token for conn controller: %w", err)
218213
}
219-
shellPath, err := DetectShell(ctx, client)
214+
shellPath, err := DetectShell(utilCtx, client)
220215
if err != nil {
221216
return err
222217
}
@@ -227,7 +222,14 @@ func (conn *WslConn) StartConnServer() error {
227222
cmdStr = fmt.Sprintf("%s=\"%s\" %s connserver --router", wshutil.WaveJwtTokenVarName, jwtToken, wshPath)
228223
}
229224
log.Printf("starting conn controller: %s\n", cmdStr)
230-
cmd := client.WslCommand(ctx, cmdStr)
225+
connServerCtx, cancelFn := context.WithCancel(context.Background())
226+
conn.WithLock(func() {
227+
if conn.cancelFn != nil {
228+
conn.cancelFn()
229+
}
230+
conn.cancelFn = cancelFn
231+
})
232+
cmd := client.WslCommand(connServerCtx, cmdStr)
231233
pipeRead, pipeWrite := io.Pipe()
232234
inputPipeRead, inputPipeWrite := io.Pipe()
233235
cmd.SetStdout(pipeWrite)

0 commit comments

Comments
 (0)