wyqydsyq
wyqydsyq

Reputation: 2020

Can't connect to mongodb locally even though mongod is running

I am unable to connect to my mongo database via external APIs or the mongo client locally, but can connect without issues from a remote host.

I am running Ubuntu 12.04, I have installed mongo from the 10gen repo. Everything was running flawlessly originally, but after restarting the server, mongo fails to connect.

My netstat returns:

    $ netstat -nap

    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      -               
    tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -               
    tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN      -               
    tcp        0      0 0.0.0.0:28017           0.0.0.0:*               LISTEN      -  

Upvotes: 0

Views: 2090

Answers (2)

TRx Studio
TRx Studio

Reputation: 33

I had the same issue running mongod 3.0.2 on Ubuntu 14.04:

MongoDB shell version: 2.4.9 Sun Apr 26 00:57:31.604 versionArrayTest passed connecting to: xxx.xxx.xxx.xxx:27000/test Sun Apr 26 00:57:31.667 creating new connection to:xxx.xxx.xxx.xxx:27000 Sun Apr 26 00:57:31.667 BackgroundJob starting: ConnectBG Sun Apr 26 00:57:31.668 connected connection! Sun Apr 26 00:57:31.671 User Assertion: 18:{ ok: 0.0, errmsg: "auth failed", code: 18 } Sun Apr 26 00:57:31.673 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:228 Sun Apr 26 00:57:31.673 User Assertion: 12514:login failed Sun Apr 26 00:57:31.673 freeing 1 uncollected N5mongo20DBClientWithCommandsE objects exception: login failed

The distribution came from MMS Mongo: https://mms.mongodb.com/

I then noticed on my MMS page, under mongod processes -> elipse menu; a menu called: "Connect to this Mongod Instance" which returned a string: "/var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.0.2/bin/mongo RBX1:27000" (RBX1 being my instance and 27000 being the port I set) Once I applied this string in my shell (I added extra user / password and authenticationDatabase parameters, and it worked.

I can now connect to my Mongod instance both locally and remotely.

Did you install MongoDB through MMS?

Upvotes: 0

sibnick
sibnick

Reputation: 4305

I gotten the same problem on CentOs 6.4 (Mongo 2.4.5, but actually it happens in other versions too). There is weird threading issue. I debugged mongo and found workaround. It is required mongo recompile. It looks like timed_wait method from boost library returns timeout when spurious wake up happened. I am not sure where bug is: mongo, boost, glibc, linux kernel.

Mongo 2.4.5 Replace in src/mongo/util/background.cpp method BackgroundJob::wait

bool BackgroundJob::wait( unsigned msTimeOut ) {
        verify( !_status->deleteSelf ); // you cannot call wait on a self-deleting job
        scoped_lock l( _status->m );
        boost::system_time const endTime = boost::get_system_time()+ boost::posix_time::milliseconds(msTimeOut);
        if ( msTimeOut ) {
            while ( _status->state != Done ) {
               if ( ! _status->finished.timed_wait( l.boost() , endTime ) ){
                  boost::system_time const curTime=boost::get_system_time();
                  if((curTime - endTime).total_milliseconds()>0){
                     return false;
                  }
                  else {
                    LOG( LL_WARNING ) << "backgroundjob " << name() << "warning: spurious wakeup return TIMEOUT code but we want wait "<<(endTime-curTime).total_milliseconds()<<" ms yet! Try again." << endl;
                  }
               }
           }
        }
        else {
           while ( _status->state != Done ) {
              _status->finished.wait( l.boost() );
           }
        }
        return true;
    }

After some time I found other problem with Perl: perl -MCPAN -e 'install "DateTime"'

Simple Perl test failed:

use strict; use warnings;

use Test::More;

use DateTime;

{ my $epochtest = DateTime->from_epoch( epoch => '997121000' ); is( $epochtest->epoch, 997121000, "epoch method returns correct value" ); }

I discovered that the problems with Perl and Mongo disappear if I remove /etc/localtime file!

Upvotes: 1

Related Questions