From 1179ea7138a3c817a8d5194ccbf9326cf650f8f8 Mon Sep 17 00:00:00 2001 From: kompotkot Date: Thu, 20 Jan 2022 11:36:24 +0000 Subject: [PATCH] Fixed bug with infinity attempts --- nodes/node_balancer/cmd/routes.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nodes/node_balancer/cmd/routes.go b/nodes/node_balancer/cmd/routes.go index d3004291..672d89e4 100644 --- a/nodes/node_balancer/cmd/routes.go +++ b/nodes/node_balancer/cmd/routes.go @@ -6,6 +6,7 @@ package cmd import ( "encoding/json" "fmt" + "log" "net/http" "strings" @@ -21,6 +22,13 @@ func pingRoute(w http.ResponseWriter, r *http.Request) { // lbHandler load balances the incoming requests to nodes func lbHandler(w http.ResponseWriter, r *http.Request) { + attempts := GetAttemptsFromContext(r) + if attempts > configs.NB_CONNECTION_RETRIES { + log.Printf("Max attempts reached from %s %s, terminating\n", r.RemoteAddr, r.URL.Path) + http.Error(w, "Service not available", http.StatusServiceUnavailable) + return + } + var blockchain string switch { case strings.HasPrefix(r.URL.Path, "/nb/ethereum"):