File tree Expand file tree Collapse file tree 2 files changed +17
-15
lines changed Expand file tree Collapse file tree 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) {
4444 if CloseStatus (closeHandshakeErr ) == - 1 {
4545 return closeHandshakeErr
4646 }
47+
4748 return nil
4849}
4950
@@ -63,23 +64,28 @@ func (c *Conn) writeClose(code StatusCode, reason string) error {
6364 Reason : reason ,
6465 }
6566
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-
6967 var p []byte
70- var err error
68+ var marshalErr error
7169 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 )
7573 }
7674 }
7775
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
8187 }
82- return werr
88+ return writeErr
8389}
8490
8591func (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=
44github.com/gobwas/pool v0.2.0 /go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw =
55github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo =
66github.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 =
97github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls =
108github.com/golang/protobuf v1.3.5 /go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk =
119github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4 =
1210github.com/google/go-cmp v0.4.0 /go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE =
1311github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM =
1412github.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 =
1713github.com/klauspost/compress v1.10.3 h1:OP96hzwJVBIHYU52pVTI6CczrxPvrGfgqF9N5eTO0Q8 =
1814github.com/klauspost/compress v1.10.3 /go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs =
1915golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs =
You can’t perform that action at this time.
0 commit comments