Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: enable golangci-lint asciicheck and bodyclose #28756

Merged
merged 5 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ linters:
- staticcheck
- stylecheck
- gosec
- asciicheck
- bodyclose
linters-settings:
staticcheck:
checks: ["S1002","S1004","S1007","S1009","S1010","S1012","S1019","S1020","S1021","S1024","S1030","SA2*","SA3*","SA4009","SA5*","SA6000","SA6001","SA6005", "-SA2002"]
Expand Down
24 changes: 17 additions & 7 deletions domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,7 @@ func doRequest(ctx context.Context, addrs []string, route, method string, body i
req.Header.Set("Content-Type", "application/json")
}

res, err = util2.InternalHTTPClient().Do(req)
failpoint.Inject("FailPlacement", func(val failpoint.Value) {
if val.(bool) {
res = &http.Response{StatusCode: http.StatusNotFound, Body: http.NoBody}
err = nil
}
})
res, err = doRequestWithFailpoint(req)
if err == nil {
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
Expand All @@ -359,6 +353,21 @@ func doRequest(ctx context.Context, addrs []string, route, method string, body i
return nil, err
}

func doRequestWithFailpoint(req *http.Request) (resp *http.Response, err error) {
fpEnabled := false
failpoint.Inject("FailPlacement", func(val failpoint.Value) {
if val.(bool) {
fpEnabled = true
resp = &http.Response{StatusCode: http.StatusNotFound, Body: http.NoBody}
err = nil
}
})
if fpEnabled {
return
}
return util2.InternalHTTPClient().Do(req)
}

// GetAllRuleBundles is used to get all rule bundles from PD. It is used to load full rules from PD while fullload infoschema.
func GetAllRuleBundles(ctx context.Context) ([]*placement.Bundle, error) {
is, err := getGlobalInfoSyncer()
Expand Down Expand Up @@ -696,6 +705,7 @@ func (is *InfoSyncer) getPrometheusAddr() (string, error) {
if err != nil {
return "", err
}
defer resp.Body.Close()
var metricStorage metricStorage
dec := json.NewDecoder(resp.Body)
err = dec.Decode(&metricStorage)
Expand Down
3 changes: 2 additions & 1 deletion executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2659,11 +2659,12 @@ func (e *TiFlashSystemTableRetriever) initialize(sctx sessionctx.Context, tiflas
if err != nil {
return errors.Trace(err)
}
_, err = util.InternalHTTPClient().Do(req)
resp, err := util.InternalHTTPClient().Do(req)
if err != nil {
sctx.GetSessionVars().StmtCtx.AppendWarning(err)
continue
}
resp.Body.Close()
e.instanceInfos = append(e.instanceInfos, tiflashInstanceInfo{
id: id,
url: url,
Expand Down
Loading