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

server: fix panic in api regions/meta #10222

Merged
merged 4 commits into from May 9, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -31,6 +31,7 @@ import (

"github.com/gorilla/mux"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/parser/model"
@@ -518,6 +519,16 @@ func (t *tikvHandlerTool) getRegionsMeta(regionIDs []uint64) ([]RegionMeta, erro
if err != nil {
return nil, errors.Trace(err)
}

failpoint.Inject("errGetRegionByIDEmpty", func(val failpoint.Value) {
if val.(bool) {
meta = nil

This comment has been minimized.

Copy link
@jackysp

jackysp Apr 22, 2019

Member

Why not return directly?

This comment has been minimized.

Copy link
@winkyao

winkyao Apr 22, 2019

Author Member

I wanna inject the case that meta is nil.

This comment has been minimized.

Copy link
@jackysp

jackysp Apr 22, 2019

Member

Is it better to inject it in GetRegionByID?

This comment has been minimized.

Copy link
@crazycs520

crazycs520 Apr 23, 2019

Contributor

@jackysp GetRegionByID function is in PD, How to inject?

This comment has been minimized.

Copy link
@jackysp

jackysp Apr 23, 2019

Member

I think there is another implement in mocktikv.

}
})

if meta == nil {
return nil, errors.Errorf("region not found for regionID %q", regionID)
}
regions[i] = RegionMeta{
ID: regionID,
Leader: leader,
@@ -29,6 +29,7 @@ import (
"time"

. "github.com/pingcap/check"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
zaplog "github.com/pingcap/log"
"github.com/pingcap/parser/model"
@@ -237,6 +238,13 @@ func (ts *HTTPHandlerTestSuite) TestRegionsFromMeta(c *C) {
for _, meta := range metas {
c.Assert(meta.ID != 0, IsTrue)
}

// test no panic
c.Assert(failpoint.Enable("github.com/pingcap/tidb/server/errGetRegionByIDEmpty", `return(true)`), IsNil)
resp1, err := http.Get("http://127.0.0.1:10090/regions/meta")
c.Assert(err, IsNil)
defer resp1.Body.Close()
c.Assert(failpoint.Disable("github.com/pingcap/tidb/server/errGetRegionByIDEmpty"), IsNil)
}

func (ts *HTTPHandlerTestSuite) startServer(c *C) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.