[SERVER-31206] SystemD services depending on mongod will be started before mongo is ready to take connections Created: 21/Sep/17  Updated: 07/Dec/17  Resolved: 07/Nov/17

Status: Closed
Project: Core Server
Component/s: Packaging
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Stephen Lynx Assignee: Mark Agarunov
Resolution: Duplicate Votes: 0
Labels: init-script, systemd
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Centos 7


Issue Links:
Duplicate
duplicates SERVER-31225 The mongod process forks before liste... Closed
Related
related to SERVER-16581 Init script should return only after ... Closed
related to SERVER-28525 SystemD services depending on mongod ... Closed
Operating System: ALL
Steps To Reproduce:

Make a systemD script that is set to start after mongod.
When the service is started, mongo won't be ready yet to take connections, causing the service to fail if it depends on that.

Participants:

 Description   

I have the following systemD script for my software:

[Unit]
Description=LynxChan
After=mongod.service
Wants=mongod.service
 
[Service]
ExecStart=/usr/bin/lynxchan
User=node
StandardOutput=syslog
Restart=on-abort
 
[Install]
WantedBy=multi-user.target

See "After=mongod.service". Because of that, my software expects mongo to be ready to take connections when it is booted by this init script.
However, for 3.4, mongo is not ready yet to take connections when my software runs.
I just tested with 3.2 and everything works as expected, my service is always able to connect to mongo when the system boots.



 Comments   
Comment by Mark Agarunov [ 07/Nov/17 ]

Hello stephenlynx,

After further investigation of this issue in SERVER-31225, I believe the cause of the issue is a missing type=forking statement in the systemd unit file. As this is detailed in SERVER-31225, I've closed this ticket as a duplicate. Please follow SERVER-31225 for updates on this issue.

Thanks,
Mark

Comment by Mark Agarunov [ 21/Sep/17 ]

Hello stephenlynx,

I've managed to reproduce this behavior with centos7 and mongodb 3.4.9. We are still investigating this behavior, however as a workaround in my testing I found a 1 second sleep added to ExecStartPre allowed enough time for MongoDB to start listening before attempting to connect.

Thanks,
Mark

Comment by Stephen Lynx [ 21/Sep/17 ]

Also, are you telling me that the new systemD init script not being able to do something basic the sysvinit script did isn't a bug?

Comment by Stephen Lynx [ 21/Sep/17 ]

So you are telling me there is NO WAY for mongod to be actually ready when the service is done starting?

Comment by Mark Agarunov [ 21/Sep/17 ]

Hello,

Thank you for the report. To have your service wait for MongoDB before starting, you could add the following line to your [Service] section:

ExecStartPre=/bin/sleep 15

This should allow enough some time for MongoDB to accept connections. Alternatively, you can modify your service to check if the socket is open before connecting, or to retry on failure to connect.

I do not see anything to indicate a bug in the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-user group.

See also our Technical Support page for additional support resources.

Thanks,
Mark

Generated at Thu Feb 08 04:26:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.