mirror of https://github.com/jetkvm/kvm.git
chore(websocket): only show warning if websocket is closed abnormally
This commit is contained in:
parent
4137b82661
commit
b71c1c4738
10
cloud.go
10
cloud.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -280,17 +281,22 @@ func runWebsocketClient() error {
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
// if the context is canceled, we don't want to return an error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, context.Canceled) {
|
||||||
|
cloudLogger.Infof("websocket connection canceled")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer c.CloseNow() //nolint:errcheck
|
defer c.CloseNow() //nolint:errcheck
|
||||||
cloudLogger.Infof("websocket connected to %s", wsURL)
|
cloudLogger.Infof("websocket connected to %s", wsURL)
|
||||||
|
|
||||||
// set the metrics when we successfully connect to the cloud.
|
// set the metrics when we successfully connect to the cloud.
|
||||||
wsResetMetrics(true, "cloud", "")
|
wsResetMetrics(true, "cloud", wsURL.Host)
|
||||||
|
|
||||||
// we don't have a source for the cloud connection
|
// we don't have a source for the cloud connection
|
||||||
return handleWebRTCSignalWsMessages(c, true, "")
|
return handleWebRTCSignalWsMessages(c, true, wsURL.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
func authenticateSession(ctx context.Context, c *websocket.Conn, req WebRTCSessionRequest) error {
|
func authenticateSession(ctx context.Context, c *websocket.Conn, req WebRTCSessionRequest) error {
|
||||||
|
|
10
web.go
10
web.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"embed"
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -251,6 +252,15 @@ func handleWebRTCSignalWsMessages(wsCon *websocket.Conn, isCloudConnection bool,
|
||||||
for {
|
for {
|
||||||
time.Sleep(WebsocketPingInterval)
|
time.Sleep(WebsocketPingInterval)
|
||||||
|
|
||||||
|
if ctxErr := runCtx.Err(); ctxErr != nil {
|
||||||
|
if !errors.Is(ctxErr, context.Canceled) {
|
||||||
|
logWarnf("websocket connection closed: %v", ctxErr)
|
||||||
|
} else {
|
||||||
|
logTracef("websocket connection closed as the context was canceled: %v")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// set the timer for the ping duration
|
// set the timer for the ping duration
|
||||||
timer := prometheus.NewTimer(prometheus.ObserverFunc(func(v float64) {
|
timer := prometheus.NewTimer(prometheus.ObserverFunc(func(v float64) {
|
||||||
metricConnectionLastPingDuration.WithLabelValues(sourceType, source).Set(v)
|
metricConnectionLastPingDuration.WithLabelValues(sourceType, source).Set(v)
|
||||||
|
|
Loading…
Reference in New Issue