Skip to content

Commit efbf5ff

Browse files
committed
fix leak of timer
1 parent a627a2f commit efbf5ff

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

client/transport/sse.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ func (c *SSE) Start(ctx context.Context) error {
110110
go c.readSSE(resp.Body)
111111

112112
// Wait for the endpoint to be received
113-
113+
timeout := time.NewTimer(30 * time.Second)
114+
defer timeout.Stop()
114115
select {
115116
case <-c.endpointChan:
116117
// Endpoint received, proceed
117118
case <-ctx.Done():
118119
return fmt.Errorf("context cancelled while waiting for endpoint")
119-
case <-time.After(30 * time.Second): // Add a timeout
120+
case <-timeout.C: // Add a timeout
120121
cancel()
121122
return fmt.Errorf("timeout waiting for endpoint")
122123
}

0 commit comments

Comments
 (0)