diff --git a/github/client.go b/github/client.go index c131d3a..2dc27ca 100644 --- a/github/client.go +++ b/github/client.go @@ -95,7 +95,7 @@ type Client struct { // accepting full URLs instead. baseURL string token string - http *http.Client + httpClient *http.Client // retryBackoff defines the delays between retry attempts for 429 responses. // retryBackoff[i] is the delay before attempt i+1 (after attempt i fails). @@ -117,7 +117,7 @@ func NewClient(token, baseURL string) *Client { return &Client{ baseURL: strings.TrimRight(baseURL, "/"), token: token, - http: &http.Client{Timeout: 30 * time.Second}, + httpClient: &http.Client{Timeout: 30 * time.Second}, now: time.Now, } } @@ -125,7 +125,7 @@ func NewClient(token, baseURL string) *Client { // SetHTTPClient sets the underlying HTTP client used for requests. // This is intended for testing to inject mock transports. func (c *Client) SetHTTPClient(hc *http.Client) { - c.http = hc + c.httpClient = hc } // SetRetryBackoff sets the delays between retry attempts. @@ -192,6 +192,7 @@ func (c *Client) doRequest(ctx context.Context, method, reqURL string, accept st timer := time.NewTimer(delay) select { case <-timer.C: + timer.Stop() case <-ctx.Done(): timer.Stop() return nil, ctx.Err() @@ -210,7 +211,7 @@ func (c *Client) doRequest(ctx context.Context, method, reqURL string, accept st req.Header.Set("Accept", "application/vnd.github+json") } - resp, err := c.http.Do(req) + resp, err := c.httpClient.Do(req) if err != nil { return nil, fmt.Errorf("do request: %w", err) }