mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 18:31:54 +00:00
Fix and enforce bodyclose lint (#19036)
This commit enables the bodyclose lint as an enforced lint, and fixes all warnings. There were a number of lint warnings for test files, but for this particular lint, it's not very valuable in tests since connection leaks just don't matter that much, and it would likely just add noise. For this reason, the lint has been disabled for `_test\.go` files. There were a few false positives, but it also caught a few cases that appear to be actual connection leaks, so I think it's still worth enabling even if it does add a small amount of noise.
This commit is contained in:
parent
da20141462
commit
dbec6d315e
@ -14,6 +14,13 @@ linters:
|
||||
- goimports
|
||||
- gosimple
|
||||
- varcheck
|
||||
- bodyclose
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- bodyclose
|
||||
|
||||
run:
|
||||
timeout: 5m
|
||||
|
||||
@ -86,6 +86,8 @@ func CountGoImporters(ctx context.Context, repo api.RepoName) (count int, err er
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
var result struct {
|
||||
Results []struct {
|
||||
Path string
|
||||
|
||||
@ -179,6 +179,7 @@ func fetchMeta(client httpcli.Doer, importPath string) (scheme string, im *impor
|
||||
resp.Body.Close()
|
||||
}
|
||||
scheme = "http"
|
||||
//nolint:bodyclose // False positive: https://github.com/timakin/bodyclose/issues/29
|
||||
resp, err = get()
|
||||
if err != nil {
|
||||
return scheme, nil, nil, err
|
||||
|
||||
@ -76,6 +76,7 @@ func search(v GQLSearchVars) (int, error) {
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("response error: %s", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
var res GraphQLResponseSearch
|
||||
if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
|
||||
return 0, fmt.Errorf("could not decode response body: %s", err)
|
||||
|
||||
@ -105,6 +105,7 @@ func (c *client) post(path string, data interface{}) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Post "+u.String())
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
//nolint:bodyclose // Body is closed in Client.Do, but the response is still returned to provide access to the headers
|
||||
package bitbucketserver
|
||||
|
||||
import (
|
||||
|
||||
@ -122,6 +122,7 @@ func (c *Client) DoJSON(method, url string, in, out interface{}) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if ct := resp.Header.Get("content-type"); !strings.HasPrefix(ct, "application/json") {
|
||||
return fmt.Errorf("content type %q is not JSON", ct)
|
||||
}
|
||||
|
||||
@ -155,6 +155,7 @@ func (s OtherSource) srcExpose(ctx context.Context) ([]*types.Repo, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user