File tree 2 files changed +17
-15
lines changed
2 files changed +17
-15
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ func (c *Conn) closeHandshake(code StatusCode, reason string) (err error) {
44
44
if CloseStatus (closeHandshakeErr ) == - 1 {
45
45
return closeHandshakeErr
46
46
}
47
+
47
48
return nil
48
49
}
49
50
@@ -63,23 +64,28 @@ func (c *Conn) writeClose(code StatusCode, reason string) error {
63
64
Reason : reason ,
64
65
}
65
66
66
- // TODO one problem with this is that if the connection is actually closed in the meantime, the error returned below will be this one lol.
67
- c .setCloseErr (fmt .Errorf ("sent close frame: %w" , ce ))
68
-
69
67
var p []byte
70
- var err error
68
+ var marshalErr error
71
69
if ce .Code != StatusNoStatusRcvd {
72
- p , err = ce .bytes ()
73
- if err != nil {
74
- log .Printf ("websocket: %v" , err )
70
+ p , marshalErr = ce .bytes ()
71
+ if marshalErr != nil {
72
+ log .Printf ("websocket: %v" , marshalErr )
75
73
}
76
74
}
77
75
78
- werr := c .writeControl (context .Background (), opClose , p )
79
- if err != nil {
80
- return err
76
+ writeErr := c .writeControl (context .Background (), opClose , p )
77
+ if CloseStatus (writeErr ) != - 1 {
78
+ // Not a real error if it's due to a close frame being received.
79
+ writeErr = nil
80
+ }
81
+
82
+ // We do this after in case there was an error writing the close frame.
83
+ c .setCloseErr (fmt .Errorf ("sent close frame: %w" , ce ))
84
+
85
+ if marshalErr != nil {
86
+ return marshalErr
81
87
}
82
- return werr
88
+ return writeErr
83
89
}
84
90
85
91
func (c * Conn ) waitCloseHandshake () error {
Original file line number Diff line number Diff line change @@ -4,16 +4,12 @@ github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8=
4
4
github.com/gobwas/pool v0.2.0 /go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw =
5
5
github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo =
6
6
github.com/gobwas/ws v1.0.2 /go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM =
7
- github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I =
8
- github.com/golang/protobuf v1.3.3 /go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw =
9
7
github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls =
10
8
github.com/golang/protobuf v1.3.5 /go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk =
11
9
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4 =
12
10
github.com/google/go-cmp v0.4.0 /go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE =
13
11
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM =
14
12
github.com/gorilla/websocket v1.4.1 /go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE =
15
- github.com/klauspost/compress v1.10.0 h1:92XGj1AcYzA6UrVdd4qIIBrT8OroryvRvdmg/IfmC7Y =
16
- github.com/klauspost/compress v1.10.0 /go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs =
17
13
github.com/klauspost/compress v1.10.3 h1:OP96hzwJVBIHYU52pVTI6CczrxPvrGfgqF9N5eTO0Q8 =
18
14
github.com/klauspost/compress v1.10.3 /go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs =
19
15
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs =
You can’t perform that action at this time.
0 commit comments