[SERVER-5457] Service install with dbpath ending in backslash results in non-runnable service. Created: 30/Mar/12 Updated: 02/Apr/15 Resolved: 02/Apr/15 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Packaging |
| Affects Version/s: | 2.0.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Mo Cassidy | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | service | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 7 SP1 |
||
| Operating System: | Windows |
| Participants: |
| Description |
|
The following command:
creates a service with a HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MongoDB\ImagePath value of:
When atetmpting to start the service using NET START Mongo27022, the following error message is given:
If I try to manually run the ImagePath value without "--service" on the end, I get the following error:
Evidently, the backslash at the end of the dbpath is being treated as an escape sequence and preventing the quotes (which were added automatically by --install !) from closing correctly. A suitable workaround is obviously to not put a backslash character at the end of the dbpath, but it definitely had me scratching my head for a bit! |
| Comments |
| Comment by Tad Marshall [ 31/Mar/12 ] | ||||
|
Thanks, Mo, those are good suggestions. I'll update the wiki page as you suggested. And you are right that the quotes that are causing the problem are ones that we added, and in the case you gave there were no spaces in the dbpath to make the quotes required. It wouldn't have made any difference if you had added quotes around your dbpath: the Windows (and C runtime?) command line processing removes them before we see the argv list and we add them to protect spaces (without checking to see if spaces are there to require them). If the dbpath you specify includes spaces, then you HAVE to provide them, otherwise we won't be given the dbpath as a single argument. (The same applies to other filespecs that include spaces, though only directories could legally include a backslash at the end). So, we could potentially only quote file and directory specifications that include spaces and we could even strip a trailing backslash from the end of directory strings like dbpath. Thanks for the detailed and easily reproducible bug report ... we'll at least document it, and maybe we can make it better! | ||||
| Comment by Mo Cassidy [ 30/Mar/12 ] | ||||
|
Thanks for the detailed explanation. That's an interesting problem. I can understand why you wouldn't want to fix it, but perhaps some warning on http://www.mongodb.org/display/DOCS/Windows+Service would be helpful. Is mongo adding the quotes itself? If it didn't add quotes automatically (and left it up the user to add quotes if there are spaces in the parameter values), then that might cut down significantly on the people affected by this, which is almost as good as building in a workaround to the problem | ||||
| Comment by Tad Marshall [ 30/Mar/12 ] | ||||
|
Thanks for the report. This is an interesting bug. This is evidently a "feature" of the Windows CommandLineToArgvW function, which is apparently used by the C runtime to prepare the argc and argv parameters that are passed to mongod.exe. The documentation describes the processing of backslashes and quotes on the command line:
See http://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx for the source of this explanation. For additional discussion, see Raymond Chen's blog: http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx . When I step through the code in the debugger, I see that we get, as a single parameter (argv[5] in my test) 'C:\data\db" --port 27022 --service' ... note the embedded quote. This also explains why the service never starts ... the "--service" parameter that tells mongod.exe to talk to the Windows Service Control Manager has been "swallowed", moved into the dbpath parameter. The only "fix" I can imagine for this is to do the parsing of the command line options ourselves and not use the argc/argv parameters we are given. This seems pretty clumsy and a heavy-handed solution and so we probably won't do this. Thanks for letting us know about this. As you figured out, not ending your path with a backslash is recommended. |