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

Commit a0606d5

Browse files
coadlerdeansheather
authored andcommitted
fix: wsnet.(*Dialer).DialContext hangs forever if ctx is cancelled (#425)
(cherry picked from commit cce7843) (cherry picked from commit ac1fdd7)
1 parent 175c42e commit a0606d5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

wsnet/dial.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,19 +386,22 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.
386386
ctx, cancel := context.WithTimeout(ctx, time.Second*5)
387387
defer cancel()
388388

389-
errCh := make(chan error)
389+
errCh := make(chan error, 1)
390390
go func() {
391+
defer close(errCh)
392+
391393
var res DialChannelResponse
392394
err = json.NewDecoder(rw).Decode(&res)
393395
if err != nil {
394396
errCh <- fmt.Errorf("read dial response: %w", err)
395397
return
396398
}
399+
397400
d.log.Debug(ctx, "dial response", slog.F("res", res))
398401
if res.Err == "" {
399-
close(errCh)
400402
return
401403
}
404+
402405
err := errors.New(res.Err)
403406
if res.Code == CodeDialErr {
404407
err = &net.OpError{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy