Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke-Rogerson committed Aug 15, 2024
1 parent 2bf25eb commit 6ecf0f5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions transport/websocket/user_order_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@ func WebSocketOrderHandler(orderSvc service.OrderBookService, getUserByApiKey mi
}
defer conn.Close()

conn.SetReadDeadline(time.Now().Add(120 * time.Second))
if err := conn.SetReadDeadline(time.Now().Add(120 * time.Second)); err != nil {
logctx.Error(ctx, "error setting initial read deadline", logger.Error(err), logger.String("userId", user.Id.String()))
http.Error(w, "Error subscribing to orders", http.StatusInternalServerError)
return
}
conn.SetPongHandler(func(appData string) error {
conn.SetReadDeadline(time.Now().Add(120 * time.Second)) // Extend deadline on pong
if err := conn.SetReadDeadline(time.Now().Add(120 * time.Second)); err != nil {
logctx.Error(ctx, "error extending read deadline", logger.Error(err), logger.String("userId", user.Id.String()))
// Not returning an error here because the connection is still valid
}
return nil
})

Expand All @@ -57,7 +64,10 @@ func WebSocketOrderHandler(orderSvc service.OrderBookService, getUserByApiKey mi

// Ensure Redis connection is unsubscribed and closed when the WebSocket disconnects
defer func() {
orderSvc.UnsubscribeUserOrders(ctx, user.Id, messageChan)
err := orderSvc.UnsubscribeUserOrders(ctx, user.Id, messageChan)
if err != nil {
logctx.Error(ctx, "error unsubscribing from user orders", logger.Error(err), logger.String("userId", user.Id.String()))
}
}()

ticker := time.NewTicker(60 * time.Second)
Expand Down

0 comments on commit 6ecf0f5

Please sign in to comment.