Skip to content

Commit a9a8df5

Browse files
committed
fix conflicts
1 parent 50d4374 commit a9a8df5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

cloud.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net/http"
99
"net/url"
10+
"sync"
1011
"time"
1112

1213
"github.com/coder/websocket/wsjson"
@@ -121,6 +122,11 @@ var (
121122
)
122123
)
123124

125+
var (
126+
cloudDisconnectChan chan error
127+
cloudDisconnectLock = &sync.Mutex{}
128+
)
129+
124130
func wsResetMetrics(established bool, sourceType string, source string) {
125131
metricConnectionLastPingTimestamp.WithLabelValues(sourceType, source).Set(-1)
126132
metricConnectionLastPingDuration.WithLabelValues(sourceType, source).Set(-1)

web.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,24 @@ func handleWebRTCSignalWsMessages(wsCon *websocket.Conn, isCloudConnection bool,
207207
}
208208
}()
209209

210+
if isCloudConnection {
211+
// create a channel to receive the disconnect event, once received, we cancelRun
212+
cloudDisconnectChan = make(chan error)
213+
defer func() {
214+
close(cloudDisconnectChan)
215+
cloudDisconnectChan = nil
216+
}()
217+
go func() {
218+
for err := range cloudDisconnectChan {
219+
if err == nil {
220+
continue
221+
}
222+
cloudLogger.Infof("disconnecting from cloud due to: %v", err)
223+
cancelRun()
224+
}
225+
}()
226+
}
227+
210228
for {
211229
typ, msg, err := wsCon.Read(runCtx)
212230
if err != nil {

0 commit comments

Comments
 (0)