File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,13 @@ import (
44 "encoding/json"
55 "net/http"
66 "strconv"
7+ "sync"
78)
89
9- var callCounts = map [string ]int {}
10+ var (
11+ callCounts = map [string ]int {}
12+ callCountsMutex sync.Mutex
13+ )
1014
1115type retriesResponse struct {
1216 Retries int `json:"retries"`
@@ -45,11 +49,13 @@ func HandleRetries(w http.ResponseWriter, r *http.Request) {
4549 return
4650 }
4751
52+ callCountsMutex .Lock ()
4853 _ , ok := callCounts [requestID ]
4954 if ! ok {
5055 callCounts [requestID ] = 0
5156 }
5257 callCounts [requestID ]++
58+ callCountsMutex .Unlock ()
5359
5460 if callCounts [requestID ] < numRetries {
5561 if retryAfter > 0 {
@@ -72,5 +78,7 @@ func HandleRetries(w http.ResponseWriter, r *http.Request) {
7278 }
7379 _ , _ = w .Write (data )
7480
81+ callCountsMutex .Lock ()
7582 delete (callCounts , requestID )
83+ callCountsMutex .Unlock ()
7684}
You can’t perform that action at this time.
0 commit comments