File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 55 "context"
66 "fmt"
77 "io"
8+ "runtime"
89 "sync"
910 "time"
1011
@@ -19,7 +20,6 @@ type controlFrame struct {
1920// Conn represents a WebSocket connection.
2021// Pings will always be automatically responded to with pongs, you do not
2122// have to do anything special.
22- // TODO set finalizer
2323type Conn struct {
2424 subprotocol string
2525 br * bufio.Reader
@@ -59,6 +59,8 @@ func (c *Conn) close(err error) {
5959 }
6060
6161 c .closeOnce .Do (func () {
62+ runtime .SetFinalizer (c , nil )
63+
6264 c .closeErr = err
6365
6466 cerr := c .closer .Close ()
@@ -82,6 +84,10 @@ func (c *Conn) init() {
8284 c .read = make (chan opcode )
8385 c .readBytes = make (chan []byte )
8486
87+ runtime .SetFinalizer (c , func (c * Conn ) {
88+ c .Close (StatusInternalError , "websocket: connection ended up being garbage collected" )
89+ })
90+
8591 go c .writeLoop ()
8692 go c .readLoop ()
8793}
You can’t perform that action at this time.
0 commit comments