# Circleci/mongo conn issue

**URL:** <https://discuss.circleci.com/t/circleci-mongo-conn-issue/30150>\
**Category:** Databases\
**Created:** [May 2, 2019, 1:23am UTC](https://discuss.circleci.com/t/circleci-mongo-conn-issue/30150 "2019-05-02T01:23:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![msolimans](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@msolimans](https://discuss.circleci.com/u/msolimans)\
**Post date:** [May 2, 2019, 1:23am UTC](https://discuss.circleci.com/t/circleci-mongo-conn-issue/30150/1 "2019-05-02T01:23:57Z")

</div>

I have a go app that needs mongo and redis as services, everything was working fine. all in a sudden mongo service is not reachable anymore. redis container is still working fine though.

I found in couple of topics that it might be a race issue, go app already started while mongo container is not completely running. so I added dockerize to wait for mongo but it gave me connection refused all the time. looks like it is something with running mongo itself inside circleci environment.

```
  docker:
      - image: circleci/golang:1.11
      - image: circleci/mongo:4.1.9
        port: 27017:27017
        environment:
          - MONGODB_USERNAME: "x"
          - MONGODB_PASSWORD: "x"
          - MONGO_INITDB_ROOT_USERNAME: "x"
          - MONGO_INITDB_ROOT_PASSWORD: "x"
      - image: circleci/redis:alpine
        port: 6379:6379
      - image: circleci/dynamodb

    steps:
      - setup_remote_docker
      - run:
          name: Waiting for Redis
          command: dockerize -wait tcp://localhost:6379 -timeout 1m
      - run:
          name: Waiting for Mongo
          command: dockerize -wait tcp://localhost:27017 -timeout 1m
      - checkout
      - run:
          name: Test  
          command: |
            ./go.test.sh

```

Any advises

---

<div class="post-metadata">

**Author:** ![stella](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@stella](https://discuss.circleci.com/u/stella)\
**Post date:** [May 3, 2019, 4:30am UTC](https://discuss.circleci.com/t/circleci-mongo-conn-issue/30150/2 "2019-05-03T04:30:49Z")

</div>

Hi,

It looks like the error is caused by the use of the MONGO\_INITDB\_ROOT\_USERNAME and MONGO\_INITDB\_ROOT\_PASSWORD environment variables, which is related to this open issue with the upstream mongo image: [https://github.com/docker-library/mongo/issues/323](https://github.com/docker-library/mongo/issues/323)

As a workaround for now, could you try removing the MONGO\_INITDB\_ROOT\_USERNAME and MONGO\_INITDB\_ROOT\_PASSWORD environment variables? The root user could be added in a separate step, for example via the following command:

```auto
# Requires installation of the mongo client
mongo --eval 'db.createUser({ user: "myrootuser", pwd: "mypassword", roles: [{ role: "userAdminAnyDatabase", db: "admin" }] });'

```

---

<div class="post-metadata">

**Author:** ![albertoperego](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/albertoperego/32/9936_2.png) [@albertoperego](https://discuss.circleci.com/u/albertoperego)\
**Post date:** [May 3, 2019, 9:00am UTC](https://discuss.circleci.com/t/circleci-mongo-conn-issue/30150/3 "2019-05-03T09:00:09Z")

</div>

I have the exact same issue as above, all of a sudden our workflow is broken and we can’t test and deploy anymore. The above solution doesn’t work for us…also it’s very generic, could you please be more specific and propose a complete solution?

---

<div class="post-metadata">

**Author:** ![albertoperego](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/albertoperego/32/9936_2.png) [@albertoperego](https://discuss.circleci.com/u/albertoperego)\
**Post date:** [May 3, 2019, 10:05am UTC](https://discuss.circleci.com/t/circleci-mongo-conn-issue/30150/4 "2019-05-03T10:05:34Z")

</div>

I doubt this is the solution to the problem, I found the same ‘FileOpenFailed’ error in a job that previously successfully ran. This issue has started to happen 30hr ago, without any change at our end in the configuration.

---

<div class="post-metadata">

**Author:** ![msolimans](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@msolimans](https://discuss.circleci.com/u/msolimans)\
**Post date:** [May 3, 2019, 2:01pm UTC](https://discuss.circleci.com/t/circleci-mongo-conn-issue/30150/5 "2019-05-03T14:01:04Z")

</div>

I fixed the issue by removing both MONGO\_INITDB\_ROOT\_USERNAME and MONGO\_INITDB\_ROOT\_PASSWORD. Also, I had to change the code as well not to use any auth.

---

<div class="post-metadata">

**Author:** ![msolimans](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@msolimans](https://discuss.circleci.com/u/msolimans)\
**Post date:** [May 3, 2019, 3:41pm UTC](https://discuss.circleci.com/t/circleci-mongo-conn-issue/30150/6 "2019-05-03T15:41:01Z")

</div>

@stella It was working before, it was broken in CircleCI all of a sudden and I don’t think it has any relation the the mongo issue you linked. from the logs I can see the mongo was up and the user was created. may be there’s something related to docker network I don’t know I couldn’t even trace the issue after I SSH to the machine because it doesn;t show current running containers even with enable\_remote\_docker

---

<div class="post-metadata">

**Author:** ![kloudd](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kloudd](https://discuss.circleci.com/u/kloudd)\
**Post date:** [May 3, 2019, 5:47pm UTC](https://discuss.circleci.com/t/circleci-mongo-conn-issue/30150/7 "2019-05-03T17:47:36Z")

</div>

@stella I am having the same issue.

```auto
MongoDB init process complete; ready for start up.

```

should come after it creates the user and roles. but it exits just before this.

When i run the same docker image in my local it works.

error in the end for pymongo when it exits. -

```auto
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

```

the container does not maintain the state also. All the processes are in defunct state. So there is no point of ssh.  
I cant even see the /proc/ logs for the mongo PID, says `access denied`.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [May 13, 2019, 5:47pm UTC](https://discuss.circleci.com/t/circleci-mongo-conn-issue/30150/8 "2019-05-13T17:47:37Z")

</div>

Closed on May 13, 2019, 5:47pm UTC

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