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 (
4
4
"encoding/json"
5
5
"net/http"
6
6
"strconv"
7
+ "sync"
7
8
)
8
9
9
- var callCounts = map [string ]int {}
10
+ var (
11
+ callCounts = map [string ]int {}
12
+ callCountsMutex sync.Mutex
13
+ )
10
14
11
15
type retriesResponse struct {
12
16
Retries int `json:"retries"`
@@ -45,11 +49,13 @@ func HandleRetries(w http.ResponseWriter, r *http.Request) {
45
49
return
46
50
}
47
51
52
+ callCountsMutex .Lock ()
48
53
_ , ok := callCounts [requestID ]
49
54
if ! ok {
50
55
callCounts [requestID ] = 0
51
56
}
52
57
callCounts [requestID ]++
58
+ callCountsMutex .Unlock ()
53
59
54
60
if callCounts [requestID ] < numRetries {
55
61
if retryAfter > 0 {
@@ -72,5 +78,7 @@ func HandleRetries(w http.ResponseWriter, r *http.Request) {
72
78
}
73
79
_ , _ = w .Write (data )
74
80
81
+ callCountsMutex .Lock ()
75
82
delete (callCounts , requestID )
83
+ callCountsMutex .Unlock ()
76
84
}
You can’t perform that action at this time.
0 commit comments