[SERVER-70705] Death Test invoked via PATH fails to exec itself Created: 19/Oct/22  Updated: 29/Oct/23  Resolved: 31/Oct/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.2.0-rc0

Type: Bug Priority: Major - P3
Reporter: David Percy Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
is caused by SERVER-61860 Death Test should exec after fork Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Service Arch 2022-10-31, Service Arch 2022-11-14
Participants:

 Description   

I have added build/install/bin/ to my PATH:

~/mongo$ echo $PATH | tr : '\n'| grep install
/home/ubuntu/mongo/build/install/bin

While this appears to work for mongod, mongo, and most unit tests, it makes death tests fail:

~/mongo$ base_test --suite ErrorExtraInfo --filter InvariantAllRegistered
...
{"t":{"$date":"2022-10-19T18:58:16.958Z"},"s":"I",  "c":"TEST",     "id":23068,   "ctx":"main","msg":"FAILURE","attr":{"failedTestsCount":1,"failedSuitesCount":1,"failedTests":["ErrorExtraInfo/InvariantAllRegistered"]}}

The child process prints this error:

{"t":{"$date":"2022-10-19T18:59:51.851Z"},"s":"I",  "c":"TEST",     "id":4680101, "ctx":"main","msg":"Result","attr":{"suite":{"name":"ErrorExtraInfo","tests":1,"fails":1,"asserts":0,"time":{"durationMillis":1},"failures":[{"test":"InvariantAllRegistered","type":"std::exception","error":"execv(avp.front(), avp.data()) failed: No such file or directory @src/mongo/unittest/death_test.cpp:247"}]}}}

When I use an explicit path, the test passes:

~/mongo$ build/install/bin/base_test --suite ErrorExtraInfo --filter InvariantAllRegistered
...
{"t":{"$date":"2022-10-19T18:58:51.490Z"},"s":"I",  "c":"TEST",     "id":23069,   "ctx":"main","msg":"SUCCESS - All tests in all suites passed"}



 Comments   
Comment by Githook User [ 31/Oct/22 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-70705 fix argv0 for DEATH_TEST exec call
Branch: master
https://github.com/mongodb/mongo/commit/73cbb4b773f896973e83a6619bcf23fae94d02b4

Comment by Billy Donahue [ 27/Oct/22 ]

+1 andrew.morrow@mongodb.com. Any program on Linux should be able to find itself as `readlink /proc/self/exe`.

Portability beyond Linux is harder.
https://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe

Comment by Andrew Morrow (Inactive) [ 20/Oct/22 ]

I don't think it is a good idea for our tests to be examining PATH like that. It opens the door to surprises about what programs are being executed, especially if you start putting multiple build trees in PATH. Suddenly, order in PATH matters, as does order of build. Maybe you aren't running the binary you think you are, leading to a lot of confusion. Instead, I'd suggest that we improve the startup logic of the test so that it "finds itself" in the filesystem no matter how it is invoked, and can then unambiguously exec itself without needing to refer back to the user environment.

Comment by David Percy [ 19/Oct/22 ]

Maybe we just have to change it from execv to execvp.

The execlp(), execvp(), and execvpe() functions duplicate the actions of the shell in searching for an executable file if the specified filename does not contain a slash character. The file is sought in the colon-separated list of directory pathnames specified in the PATH environment variable.

Generated at Thu Feb 08 06:16:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.