Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit cce7843

Browse files
authored
fix: wsnet.(*Dialer).DialContext hangs forever if ctx is cancelled (#425)
1 parent 1f35561 commit cce7843

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

wsnet/dial.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,22 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.
392392
ctx, cancel := context.WithTimeout(ctx, time.Second*5)
393393
defer cancel()
394394

395-
errCh := make(chan error)
395+
errCh := make(chan error, 1)
396396
go func() {
397+
defer close(errCh)
398+
397399
var res DialChannelResponse
398400
err = json.NewDecoder(rw).Decode(&res)
399401
if err != nil {
400402
errCh <- fmt.Errorf("read dial response: %w", err)
401403
return
402404
}
405+
403406
d.log.Debug(ctx, "dial response", slog.F("res", res))
404407
if res.Err == "" {
405-
close(errCh)
406408
return
407409
}
410+
408411
err := errors.New(res.Err)
409412
if res.Code == CodeDialErr {
410413
err = &net.OpError{

0 commit comments

Comments
 (0)