File tree 1 file changed +20
-1
lines changed
1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -161,12 +161,15 @@ func (c *Client) Listen(ctx context.Context) (net.Conn, error) {
161
161
return nil , codersdk .ReadBodyAsError (res )
162
162
}
163
163
164
+ ctx , cancelFunc := context .WithCancel (ctx )
164
165
ctx , wsNetConn := websocketNetConn (ctx , conn , websocket .MessageBinary )
165
166
166
167
// Ping once every 30 seconds to ensure that the websocket is alive. If we
167
168
// don't get a response within 30s we kill the websocket and reconnect.
168
169
// See: https://github.com/coder/coder/pull/5824
170
+ closed := make (chan struct {})
169
171
go func () {
172
+ defer close (closed )
170
173
tick := 30 * time .Second
171
174
ticker := time .NewTicker (tick )
172
175
defer ticker .Stop ()
@@ -199,7 +202,13 @@ func (c *Client) Listen(ctx context.Context) (net.Conn, error) {
199
202
}
200
203
}()
201
204
202
- return wsNetConn , nil
205
+ return & closeNetConn {
206
+ Conn : wsNetConn ,
207
+ closeFunc : func () {
208
+ cancelFunc ()
209
+ <- closed
210
+ },
211
+ }, nil
203
212
}
204
213
205
214
type PostAppHealthsRequest struct {
@@ -623,3 +632,13 @@ type StartupLogsNotifyMessage struct {
623
632
CreatedAfter int64 `json:"created_after"`
624
633
EndOfLogs bool `json:"end_of_logs"`
625
634
}
635
+
636
+ type closeNetConn struct {
637
+ net.Conn
638
+ closeFunc func ()
639
+ }
640
+
641
+ func (c * closeNetConn ) Close () error {
642
+ c .closeFunc ()
643
+ return c .Conn .Close ()
644
+ }
You can’t perform that action at this time.
0 commit comments