MongoDB Fails On Reboot - Socket Exception & Unable to Access Unless SSHd

After a few folks within the community assisted in fixing a previous error, I am having an error on boot. From what I’ve found, this error happens when trying to assign an IP that is not available on the local interface. The computer used to access the DB is on the same network as the Pi, so it doesn’t travel outside the network and doesn’t need a VPN/proxy/etc of some kind to connect.

Device Information:
Raspberry Pi 5 using Ubuntu Server 24.04 LTS

Specific Error:

{"t":{"$date":"2024-06-10T08:14:20.621-05:00"},"s":"E",  "c":"CONTROL",  "id":20568,   "ctx":"initandlisten","msg":"Error setting up listener","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"setup bind :: caused by :: Cannot assign requested address"}}}

I’ve ran the command " ifconfig -a | grep “inet” " and the output is as follows:

inet  netmask  broadcast
inet6 fe80::2ecf:67ff:fe2e:a51e  prefixlen 64  scopeid 0x20<link>
inet  netmask
inet6 ::1  prefixlen 128  scopeid 0x10<host>

I’ve removed the “,” portion of the bindIP, and it would start just fine after a reboot, and I can manually start the service with no issues with that IP in the config file.

When attempting to access it in CMD/another platform without being SSH’d first, I get the following error:

Current Mongosh Log ID: 66688ede9d0be543b746b798
Connecting to:          mongodb://<credentials>@
MongoServerSelectionError: connect ETIMEDOUT

Log File - Unable to upload file so hastebin is being used

Config File

Mongod.service file

It is normal that you cannot listen to an IP for which is there is no interface. That is why it starts fine when you remove from the mongod.service file.

At the same if ifconfig shows you the address and you can start manually with it, it then means that you have another systemd service that brings that interface up.

You will have to find which systemd unit initialize the desired IP and update the mongod service file to ensure that is run only after the other is started with Requires= and After= or Wants=.

Isn’t that what the following line does in the service file?

I did try the following but I get the same result as well:,sys-devices-virtual-net-lan0.device,sys-devices-virtual-net-lan0.device

Everything else is the same

I thought that the value separator in unit files was the semicolon, but I might be wrong.

I do not know your system so I do not know what unit brings the up so I do not know what dependencies you need.

I just looked at the documentation for it, and it’s space-separated values, or I can use multiple lines; I just assumed it was a comma as that tends to be the go-to separator.

I’ve corrected the service file; the result is that it failed to start due to dependency.

Would you know how to find out what service starts the network interface?

Hi @Joe_Swanson

As far as I understand it, the following dependencies in the unit file should be fine:

Obviously you’ll want to fix the startup order problem, if that’s what’s happening, but what happens if you manually start mongod with systemct start mongod? Once your machine has finished booting, the IP should be available, so that command should work fine when you run it manually. Does it?

If it doesn’t that implies that something has already bound to port 27017, which would explain why mongod is failing to bind to it.

MongoDB maintains a working systemd configuration.

My apologies; I thought I had already included that I could start it normally once the machine is fully booted. I ended up doing what this comment said and did bindIpAll: true as it doesn’t impact security at all.


So does that mean that (a) mongod starts correctly at boot time, and (b) you can connect from another machine on the same network without using SSH tunnelling?

I’m unable to connect without SSH tunneling still, unfortunately, and Mongod starts correctly on boot.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.