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

globalsign/mgo: panic #870

Closed
kokizzu opened this issue Mar 15, 2021 · 2 comments · Fixed by #937
Closed

globalsign/mgo: panic #870

kokizzu opened this issue Mar 15, 2021 · 2 comments · Fixed by #937
Labels
apm:ecosystem contrib/* related feature requests or bugs bug unintended behavior that has to be fixed

Comments

@kokizzu
Copy link

kokizzu commented Mar 15, 2021

I've tried connection string (from Go) with nodejs and it works successfully (after escaping the password):

    const {MongoClient} = require('mongodb');
    (new MongoClient('mongodb://rwuser:1vK6c6%7Dc24Rr%28%2A%[email protected].:27017/mongodbtest1?connectTimeoutMS=1000&wtimeoutMS=1000')).connect()

but when I tried the exact connection string, which is generated from this code:

    func (c ConnectOption) ToUrl() string {
      ms := timeout.Milliseconds()
	  res := fmt.Sprintf("mongodb://%s:%s@%s/%s?connectTimeoutMS=%d&wtimeoutMS=%d", 
        c.Username, url.QueryEscape(c.Password), c.Hosts, c.DBName, ms, ms)
      return res
    }

it shows exact same error error as when the password not escaped:

     panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x80 pc=0x8dd963]
    goroutine 1 [running]:
    sync.(*RWMutex).RLock(...)
        /usr/local/go/src/sync/rwmutex.go:48
    github.com/globalsign/mgo.(*Session).acquireSocket(0x0, 0x42ed01, 0x0, 0x0, 0x0)
        /go/pkg/mod/github.com/globalsign/[email protected]/session.go:5101 +0x53
    github.com/globalsign/mgo.(*Database).Run(0xc00074d868, 0xb912c0, 0xc00072c4a0, 0xb866c0, 0xc00016a230, 0x0, 0x0)
        /go/pkg/mod/github.com/globalsign/[email protected]/session.go:992 +0x53
    github.com/globalsign/mgo.(*Session).Run(0x0, 0xb912c0, 0xc00072c4a0, 0xb866c0, 0xc00016a230, 0xc0001965a0, 0xc00074d918)
        /go/pkg/mod/github.com/globalsign/[email protected]/session.go:2489 +0x8a
    github.com/globalsign/mgo.(*Session).BuildInfo(0x0, 0xb7, 0x0, 0xd95b40, 0xc0001965a0, 0x203000, 0x203000, 0x203000, 0x0, 0xc00074da80, ...)
        /go/pkg/mod/github.com/globalsign/[email protected]/session.go:5071 +0x101
    gopkg.in/DataDog/dd-trace-go.v1/contrib/globalsign/mgo.Dial(0xc000758000, 0xb7, 0xc00074db18, 0x2, 0x2, 0xc00002634c, 0xd, 0xc0000262cc)
        /go/pkg/mod/gopkg.in/!data!dog/[email protected]/contrib/globalsign/mgo/mgo.go:25 +0x80
    dummyproject/testmongo1/database/mongodb.Client(0xc00002205e, 0x39, 0xc00002a128, 0x22, 0x0, 0xc00002634c, 0xd, 0xc0000262cc, 0x14, 0xc00074dc00, ...)
        /go/src/dummyproject/testmongo1/database/mongodb/mongodb.go:67 +0x14c
    dummyproject/testmongo1/database/mongodb.DBFromEnv(0xc8050f)
        /go/src/dummyproject/testmongo1/database/mongodb/mongodb.go:155 +0x1dc
    dummyproject/testmongo1/database.InitDatabase()
        /go/src/dummyproject/testmongo1/database/database.go:15 +0xa4
    dummyproject/testmongo1.Newtestmongo1(0xc00074ded8)
        /go/src/dummyproject/testmongo1/testmongo1.go:43 +0x177
    main.main()
        /go/src/dummyproject/testmongo1/app/web/main.go:24 +0x8a

It runs on alpine docker, what's the other possible cause?

The lines testmongo1/database/mongodb/mongodb.go:67 are:

    session, err := mgo.Dial(opt.ToUrl(timeout()), 
        mgo.WithServiceName(`cinderella-mongo`),
		mgo.WithAnalytics(true))

mgo is a package, opt is not nil, timeout() returns concrete time.Duration, so there's no way that it's that line's that causes the error.

@gbbr
Copy link
Contributor

gbbr commented Mar 16, 2021

Have you tried posting this issue on the globalsign/mgo repository? Based on the stack trace it seems like the problem is coming from there...

@gbbr gbbr changed the title How to correctly use mgo+datadog? globalsign/mgo: panic Mar 16, 2021
@knusbaum
Copy link
Contributor

@kokizzu

Based on your trace, I believe I see that we're calling BuildInfo on a nil mgo.(*Session) object on this line

It looks like we don't check the err return before using the *Session.

    github.com/globalsign/mgo.(*Session).BuildInfo(0x0, 0xb7, 0x0, 0xd95b40, 0xc0001965a0, 0x203000, 0x203000, 0x203000, 0x0, 0xc00074da80, ...)
        /go/pkg/mod/github.com/globalsign/[email protected]/session.go:5071 +0x101

@knusbaum knusbaum added bug unintended behavior that has to be fixed apm:ecosystem contrib/* related feature requests or bugs labels May 26, 2021
knusbaum added a commit that referenced this issue Jul 22, 2021
…937)

This commit fixes a bug causing a panic when mgo fails to dial the database.

Fixes #870
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:ecosystem contrib/* related feature requests or bugs bug unintended behavior that has to be fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants