fix bugs from todo except first critical

This commit is contained in:
gitGnome
2026-03-27 12:27:05 +01:00
parent 04da887e4d
commit a6a19dad6e
3 changed files with 23 additions and 8 deletions
+9 -5
View File
@@ -20,13 +20,14 @@ func ServeWsConnection(responseWriter http.ResponseWriter, request *http.Request
return
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var client = Client{WsConn: connection}
var isAuthenticated bool
var ignoreCache bool
defer closeConnection(&client)
defer closeConnection(&client, ignoreCache)
for {
var clientMessage map[string]any
err := wsjson.Read(ctx, connection, &clientMessage)
@@ -42,6 +43,7 @@ func ServeWsConnection(responseWriter http.ResponseWriter, request *http.Request
}
} else {
if !handleUnauthenticatedMessage(&client, &clientMessage) {
ignoreCache = true
return
}
isAuthenticated = true
@@ -57,7 +59,7 @@ func sendMessageCloseIfTimeout(client *Client, message *map[string]any) {
err := wsjson.Write(ctx, client.WsConn, message)
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
closeConnection(client)
closeConnection(client, false)
}
log.Printf("write error: %v", err)
}
@@ -111,7 +113,9 @@ func handleUnauthenticatedMessage(client *Client, clientMessage *map[string]any)
return true
}
func closeConnection(client *Client) {
CacheDeleteClient(client.Id)
func closeConnection(client *Client, ignoreCache bool) {
if !ignoreCache {
CacheDeleteClient(client.Id)
}
client.WsConn.CloseNow()
}