[SERVER-31225] The mongod process forks before listening for connections Created: 22/Sep/17 Updated: 30/Oct/23 Resolved: 01/Dec/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 3.4.9 |
| Fix Version/s: | 3.4.11, 3.6.1, 3.7.1 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Mark Agarunov | Assignee: | Mathew Robinson (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
|||||||||||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | |||||||||||||||||||||||||||||||||
| Operating System: | ALL | |||||||||||||||||||||||||||||||||
| Backport Requested: |
v3.6, v3.4
|
|||||||||||||||||||||||||||||||||
| Steps To Reproduce: | Create a systemd service to test if the socket is listening:
With the following script (/usr/bin/testsocket)
Stop mongod, and start the service which should start mongod first:
Add a 1 second sleep via ExecStartPre in the testservice unit file, or to the beginning of /usr/bin/testsocket and mongod is listening by the time it runs:
|
|||||||||||||||||||||||||||||||||
| Sprint: | Build Ready | |||||||||||||||||||||||||||||||||
| Participants: | ||||||||||||||||||||||||||||||||||
| Description |
|
When starting mongod as a systemd service, the process forks before mongod has opened the socket and starts listening for connections. This can cause dependent services to fail to start, as systemd considers mongod started once the process has forked. |
| Comments |
| Comment by Githook User [ 05/Dec/17 ] | ||||||||||||||||||||||
|
Author: {'username': 'chasinglogic', 'email': 'chasinglogic@gmail.com', 'name': 'Mathew Robinson'}Message: | ||||||||||||||||||||||
| Comment by Githook User [ 30/Nov/17 ] | ||||||||||||||||||||||
|
Author: {'name': 'Mathew Robinson', 'username': 'chasinglogic', 'email': 'chasinglogic@gmail.com'}Message: | ||||||||||||||||||||||
| Comment by Githook User [ 30/Nov/17 ] | ||||||||||||||||||||||
|
Author: {'name': 'Mathew Robinson', 'username': 'chasinglogic', 'email': 'chasinglogic@gmail.com'}Message: | ||||||||||||||||||||||
| Comment by Mathew Robinson (Inactive) [ 29/Nov/17 ] | ||||||||||||||||||||||
|
I was able to reproduce using the systemd files from our packages:
With Type=forking:
| ||||||||||||||||||||||
| Comment by Mark Agarunov [ 06/Oct/17 ] | ||||||||||||||||||||||
|
ernie.hershey, I confirmed that mongod does start listening before forking. This should more or less match the behavior of systemd with Type=forking:
I believe that the Type=forking will fix this, as without it systemd will treat mongod as Type=simple:
I reproduced this by launching mongod in a subshell:
which matches the behavior without Type=forking. | ||||||||||||||||||||||
| Comment by Ernie Hershey [ 06/Oct/17 ] | ||||||||||||||||||||||
|
henrik.edin are you certain that doing that will make Mark's reproduction case succeed? I think it will still fork early. | ||||||||||||||||||||||
| Comment by Henrik Edin [ 02/Oct/17 ] | ||||||||||||||||||||||
|
I've been investigating this with mark.agarunov and it seems that the core issue is that the default mongod.service file doesn't have
By default systemd is using a 'simple' type where the process is forked automatically at start which is what causing this issue. While looking into this it also seems like the default debian mongod.service and mongod.conf doesn't set fork: true in the processManagement block. |