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

Panic in dbtest #117

Closed
nim-nim opened this issue Feb 28, 2018 · 8 comments
Closed

Panic in dbtest #117

nim-nim opened this issue Feb 28, 2018 · 8 comments

Comments

@nim-nim
Copy link

nim-nim commented Feb 28, 2018

While running unit tests with go 1.9.4 on x86_64 for release 2018.02.20

+ go test -buildmode pie -compiler gc -ldflags ' -X github.com/globalsign/mgo/version.tag=r2018.02.20 -X github.com/globalsign/mgo/version=2018.02.20 -extldflags '\''-Wl,-z
,relro  '\'''

----------------------------------------------------------------------
PANIC: dbserver_test.go:89: S.TestCheckSessions

... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x55E276888F1C)

/usr/lib/golang/src/runtime/panic.go:491
  in gopanic
/usr/lib/golang/src/runtime/panic.go:63
  in panicmem
/usr/lib/golang/src/runtime/signal_unix.go:367
  in sigpanic
/usr/lib/golang/src/os/exec_unix.go:56
  in Process.signal
/usr/lib/golang/src/os/exec.go:121
  in Process.Signal
dbserver.go:114
  in DBServer.Stop
/usr/lib/golang/src/runtime/panic.go:491
  in gopanic
dbserver.go:72
  in DBServer.start
dbserver.go:130
  in DBServer.Session
dbserver_test.go:94
  in S.TestCheckSessions
/usr/lib/golang/src/reflect/value.go:302
  in Value.Call
/usr/lib/golang/src/runtime/asm_amd64.s:2337
  in goexit

----------------------------------------------------------------------
PANIC: dbserver_test.go:99: S.TestCheckSessionsDisabled

... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x55E276888F1C)

/usr/lib/golang/src/runtime/panic.go:491
  in gopanic
/usr/lib/golang/src/runtime/panic.go:63
  in panicmem
/usr/lib/golang/src/runtime/signal_unix.go:367
  in sigpanic
/usr/lib/golang/src/os/exec_unix.go:56
  in Process.signal
/usr/lib/golang/src/os/exec.go:121
  in Process.Signal
dbserver.go:114
  in DBServer.Stop
/usr/lib/golang/src/runtime/panic.go:491
  in gopanic
dbserver.go:72
  in DBServer.start
dbserver.go:130
  in DBServer.Session
dbserver_test.go:107
  in S.TestCheckSessionsDisabled
/usr/lib/golang/src/reflect/value.go:302
  in Value.Call
/usr/lib/golang/src/runtime/asm_amd64.s:2337
  in goexit

----------------------------------------------------------------------
PANIC: dbserver_test.go:58: S.TestStop

... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x55E276888F1C)

/usr/lib/golang/src/runtime/panic.go:491
  in gopanic
/usr/lib/golang/src/runtime/panic.go:63
  in panicmem
/usr/lib/golang/src/runtime/signal_unix.go:367
  in sigpanic
/usr/lib/golang/src/os/exec_unix.go:56
  in Process.signal
/usr/lib/golang/src/os/exec.go:121
  in Process.Signal
dbserver.go:114
  in DBServer.Stop
/usr/lib/golang/src/runtime/panic.go:491
  in gopanic
dbserver.go:72
  in DBServer.start
dbserver.go:130
  in DBServer.Session
dbserver_test.go:67
  in S.TestStop
/usr/lib/golang/src/reflect/value.go:302
  in Value.Call
/usr/lib/golang/src/runtime/asm_amd64.s:2337
  in goexit

----------------------------------------------------------------------
PANIC: dbserver_test.go:35: S.TestWipeData

... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x55E276888F1C)

/usr/lib/golang/src/runtime/panic.go:491
  in gopanic
/usr/lib/golang/src/runtime/panic.go:63
  in panicmem
/usr/lib/golang/src/runtime/signal_unix.go:367
  in sigpanic
/usr/lib/golang/src/os/exec_unix.go:56
  in Process.signal
/usr/lib/golang/src/os/exec.go:121
  in Process.Signal
dbserver.go:114
  in DBServer.Stop
/usr/lib/golang/src/runtime/panic.go:491
  in gopanic
dbserver.go:72
  in DBServer.start
dbserver.go:130
  in DBServer.Session
dbserver_test.go:40
  in S.TestWipeData
/usr/lib/golang/src/reflect/value.go:302
  in Value.Call
/usr/lib/golang/src/runtime/asm_amd64.s:2337
  in goexit
--- FAIL: TestAll (0.00s)
FAIL
OOPS: 0 passed, 4 PANICKED
exit status 1
FAIL    github.com/globalsign/mgo/dbtest        0.011s

A unit test should always just work with go test and report sensible results

@dennypenta
Copy link

It looks like you didn't initialize a mgo.Session.

@nim-nim
Copy link
Author

nim-nim commented Mar 1, 2018

I just executed the unit test

Unit tests are supposed to be autonomous

@tadukurow
Copy link

These are integration tests, which means they will use mongodb installed on the system.

The exec.Cmd, invoking mongod, fails and wraps the error it gets in a panic.
That panic is caught in a panic handler, which tries to stop the unstarted DB which causes the nil dereference panic.
Ugly for sure, but it does not look like broken tests.

Initial exec.Cmd failing is at:

dbserver.go:72
  in DBServer.start

This is most likely a configuration issue on your testing machine, such as mongod not being on the path. Can you ensure mongod can be executed by the user running the test?

The dbtest package is not used very much and we would welcome any contribution, that would make the test setup more robust/debuggable.

@domodwyer
Copy link

Hi @nim-nim

I'm going to close this because it sounds like @tadukurow has found the issue - feel free to reply if there's still something else happening though.

Dom

@jtbonhomme
Copy link

jtbonhomme commented Mar 10, 2018

Hi @domodwyer !

I have the same problem. Mongo is actually in my $PATH but it does not seem to start mongo.

$ which mongod
/usr/local/bin/mongod
$ echo $PATH
/Users/jtbonhomme/.pyenv/shims:/Users/jtbonhomme/.pyenv/shims:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/X11/bin:/usr/local/share/npm/bin:/Users/jtbonhomme/.rvm/bin:/Users/jtbonhomme/Developments/golang/bin:/usr/local/opt/go/libexec/bin

Thank you,
JT

@nim-nim
Copy link
Author

nim-nim commented Mar 10, 2018

I had figured it needed mongod in the path, and as you noted this is not sufficient

As running mongod is a privileged operation on my system, I can't see how I could possibly run this test.

@tadukurow
Copy link

@nim-nim, the dbtest package is used for creating integration tests in other test suites.
If you're unable to run mongod to execute dbtest, best to skip them as they will always need to execute local mongo for them to be meaningful.

@jtbonhomme, executing locally works for me, so it's probably some environment issue. I did find a test assertion error which is fixed in #122.
I've also updated the server start command to print the error to stderr, before throwing the panic.
See second line on the sample output below.
If you run the branch, it should give you more insight why mongod could not be executed.

=== RUN   TestAll
mongod failed to start: exec: "mongod": executable file not found in $PATH

----------------------------------------------------------------------
PANIC: dbserver_test.go:87: S.TestCheckSessions

... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x105A86A)

/usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491
  in gopanic
/usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:63
  in panicmem
/usr/local/Cellar/go/1.9.2/libexec/src/runtime/signal_unix.go:367
  in sigpanic
/usr/local/Cellar/go/1.9.2/libexec/src/os/exec_unix.go:56
  in Process.signal
/usr/local/Cellar/go/1.9.2/libexec/src/os/exec.go:121
  in Process.Signal
dbserver.go:116
  in DBServer.Stop
/usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491
  in gopanic
dbserver.go:74
  in DBServer.start
dbserver.go:132
  in DBServer.Session
dbserver_test.go:92
  in S.TestCheckSessions
/usr/local/Cellar/go/1.9.2/libexec/src/reflect/value.go:302
  in Value.Call
/usr/local/Cellar/go/1.9.2/libexec/src/runtime/asm_amd64.s:2337
  in goexit
mongod failed to start: exec: "mongod": executable file not found in $PATH

----------------------------------------------------------------------

tadukurow added a commit that referenced this issue Mar 12, 2018
As seen in #117, dbtest start() throws a panic when it can't start mongo.
This panic is picked up by a panichandler obscuring the actual problem.
This PR simply prints the error start() encounters to stderr, before throwing the panic.
domodwyer pushed a commit that referenced this issue Mar 12, 2018
* Ignore dial error when server is stopped. related to #117

* Print dbtest server starting error before panic.

As seen in #117, dbtest start() throws a panic when it can't start mongo.
This panic is picked up by a panichandler obscuring the actual problem.
This PR simply prints the error start() encounters to stderr, before throwing the panic.
@nim-nim
Copy link
Author

nim-nim commented Mar 12, 2018

Thank you, a clearer test failure certainly help (though the test should PASS when its prerequisites can't be set up)

libi pushed a commit to libi/mgo that referenced this issue Dec 1, 2022
* Ignore dial error when server is stopped. related to globalsign#117

* Print dbtest server starting error before panic.

As seen in globalsign#117, dbtest start() throws a panic when it can't start mongo.
This panic is picked up by a panichandler obscuring the actual problem.
This PR simply prints the error start() encounters to stderr, before throwing the panic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants