Skip to content

Commit b312f7b

Browse files
Denys Smirnovdennwc
authored andcommitted
net/ws: wait for the connection close event when dialing fails
1 parent f24932c commit b312f7b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

net/ws/wsconn_js.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ func Dial(addr string) (net.Conn, error) {
3939
if !ev.Data.Get("message").IsUndefined() {
4040
return nil, fmt.Errorf("ws.dial: %v", js.NewError(ev.Data))
4141
}
42-
select {
43-
case ce := <-c.events:
44-
if ce.Type == eventClosed {
45-
code := ce.Data.Get("code").Int()
46-
return nil, fmt.Errorf("ws.dial: connection closed with code %d", code)
47-
}
48-
default:
42+
// after an error the connection should switch to a closed state
43+
ev = <-c.events
44+
if ev.Type == eventClosed {
45+
// unfortunately there is no way to get the real cause of an error
46+
code := ev.Data.Get("code").Int()
47+
return nil, fmt.Errorf("ws.dial: connection closed with code %d", code)
4948
}
5049
return nil, fmt.Errorf("ws.dial: connection failed, see console")
5150
}

0 commit comments

Comments
 (0)