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

pd-client: fix a nil pointer dereference #838

Merged
merged 2 commits into from Nov 8, 2017

Conversation

Projects
None yet
4 participants
@tiancaiamao
Contributor

tiancaiamao commented Nov 7, 2017

There is a bug in last commit: I've thought all requests to be with or without span information in context, and check the first one to determine that.

if len(requests) > 0 && opentracing.SpanFromContext(requests[0].ctx) != nil {
	opts := make([]opentracing.StartSpanOption, 0, len(requests))
	for _, req := range requests {
		span := opentracing.SpanFromContext(req.ctx)  // SPAN MAYBE NIL !!!
		opts = append(opts, opentracing.ChildOf(span.Context()))
	}
	span := opentracing.StartSpan("pdclient.processTSORequests", opts...)
	defer span.Finish()
}

but actually I meet cases where some context have span and some not, then TiDB panic on nil pointer dereference:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0xe87631]

goroutine 73 [running]:
github.com/pingcap/pd/pd-client.(*client).processTSORequests(0xc42012b4d0, 0x18e9200, 0xc4202c40c0, 0xc422c76c00, 0x2, 0x80, 0x0, 0x0)
        /home/nnzhou/go/src/github.com/pingcap/tidb/_vendor/src/github.com/pingcap/pd/pd-client/client.go:352 +0x141
github.com/pingcap/pd/pd-client.(*client).tsLoop(0xc42012b4d0)
        /home/nnzhou/go/src/github.com/pingcap/tidb/_vendor/src/github.com/pingcap/pd/pd-client/client.go:330 +0x3a0
created by github.com/pingcap/pd/pd-client.NewClient
        /home/nnzhou/go/src/github.com/pingcap/tidb/_vendor/src/github.com/pingcap/pd/pd-client/client.go:121 +0x457

@disksing @siddontang

@siddontang

This comment has been minimized.

Show comment
Hide comment
@siddontang

siddontang Nov 7, 2017

Member

LGTM

Member

siddontang commented Nov 7, 2017

LGTM

@disksing

This comment has been minimized.

Show comment
Hide comment
@disksing

disksing Nov 7, 2017

Member

LGTM. Please make CI pass.

Member

disksing commented Nov 7, 2017

LGTM. Please make CI pass.

@nolouch

nolouch approved these changes Nov 8, 2017

LGTM

@siddontang siddontang merged commit 47d8f72 into pingcap:master Nov 8, 2017

3 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla Contributor License Agreement is signed.
Details

@tiancaiamao tiancaiamao deleted the tiancaiamao:fix-null-pointer branch Nov 8, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment