Skip to content

Commit cbc0df8

Browse files
authored
Increase events timeout to 10s, use one timeout per retry (#265)
- Change our events client timeout from 5s to 10s - Each retry now uses a new timeout context instead of one for all of the them
1 parent 275e497 commit cbc0df8

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

internal/metrics/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"go.uber.org/zap"
1818
)
1919

20-
const timeout = 5 * time.Second
20+
const timeout = 10 * time.Second
2121
const maxIdleConnsPerHost = 32
2222
const maxConnsPerHost = 32
2323
const maxRetries = 5
@@ -103,15 +103,15 @@ func (c *Client) RecordEvent(ctx context.Context, params EventParams) {
103103
idempotency := xid.New().String()
104104
logger = logger.With(zap.String("idempotency", idempotency))
105105

106-
// Use a new context, we want to record events of users that are already disconnected.
107-
ctx, cancel := context.WithTimeout(context.Background(), timeout)
108-
defer cancel()
109-
110106
for i := range maxRetries {
111107
if i > 0 {
112108
time.Sleep(time.Duration(rand.Int63n(backoffRange)*int64(i)) * time.Millisecond)
113109
}
114110

111+
// Use a new context, we want to record events of users that are already disconnected.
112+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
113+
defer cancel()
114+
115115
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.url, bytes.NewReader(payload))
116116
if err != nil {
117117
logger.Error("failed to create metrics request", zap.Error(err))

0 commit comments

Comments
 (0)