0

I have mongodb running on Linux 7. Java client from a remote system tries using Driver 3.0.2 to connect to it using code as shown below:

 mongoClient = new MongoClient(new ServerAddress("10.12.22.22", 27017),
                               new MongoClientOptions.Builder().connectTimeout(300000).socketTimeout(300000).build());

The result is the following exception:

**INFO: Exception in monitor thread while connecting to server 10.12.22.22:27017
com.mongodb.MongoSocketOpenException: Exception opening socket**
    at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
    at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
    at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
    at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
    ... 3 more

Java Client running on windows: 10.12.22.116 Mongo DB running on Linux: 10.12.22.22: 27017

When the Java client is executed, tcpdump on linux system clearly shows packets reaching mongo db process but still no response from db.

[root@localhost ~]# tcpdump -i enp0s3 port 27017 -vv

tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 65535 bytes00:22:40.026816 IP (tos 0x0, ttl 128, id 8435, offset 0, flags [DF], proto TCP (6), length 52)
    10.12.22.116.12364 > 10.12.22.22.27017: Flags [S], cksum 0xdd04 (correct), seq 1967333969, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
00:22:43.026954 IP (tos 0x0, ttl 128, id 8437, offset 0, flags [DF], proto TCP (6), length 52)
    10.12.22.116.12364 > 10.12.22.22.27017: Flags [S], cksum 0xdd04 (correct), seq 1967333969, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
00:22:49.028216 IP (tos 0x0, ttl 128, id 8439, offset 0, flags [DF], proto TCP (6), length 48)

MongodB is listening at target port as shown below:

[root@localhost ~]# netstat -tunlep

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      0          20288      2360/master         
tcp        0      0 10.12.22.22:27017       0.0.0.0:*               LISTEN      1001       27947      3220/mongod**         
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      1001       27945      3220/mongod    

There is no firewall active as well (checked using iptables -L -n)

Please see what is missing here which is causing this issue?

4
  • We welcome you on SO. Please see How do I ask a good question? Commented Aug 10, 2015 at 8:08
  • There is something rather strange, since two instances of mongod seem to be bound on different IPs, but the same port. Please add the result of ps axu | grep [m]ongod and the content of your mongod.conf. Furthermore, what is the result of telnet 10.12.22.22 27017 when executed on the client? As a side node: postfix should not be run as root, iirc. Commented Aug 10, 2015 at 8:33
  • Result of 'ps axu | grep [m]ongod' is :ps axu | grep [m]ongod ultrama+ 3220 0.3 7.1 657260 72764 pts/0 Sl Aug10 0:35 mongod -f /etc/mongod.conf Two ips are shown because in mongo.conf I have mentioned two ips as I need to connect remotely from Java client : net: bindIp: 127.0.0.1,10.12.22.22 port: 27017 Commented Aug 10, 2015 at 9:48
  • Full conf is: [root@localhost ~]# cat /etc/mongod.conf processManagement: fork: false net: bindIp: 127.0.0.1,10.12.22.22 port: 27017 storage: dbPath: /data/db systemLog: destination: file path: "/var/log/mongodb/mongod.log" logAppend: true component: network: verbosity: 5 storage: journal: enabled: true Commented Aug 10, 2015 at 9:53

1 Answer 1

1

Finally it comes out that Linux firewall was blocking it. I disabled it using

service iptables stop
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.