supercharge / mongodb-github-action

Use MongoDB in GitHub Actions
MIT License
222 stars 46 forks source link

Connection timeout #30

Closed jorgeluisrezende closed 2 years ago

jorgeluisrezende commented 2 years ago

I've trying to use this action, but my application are not connecting on mongo db, Im receving a timeout error.

|     MongoServerSelectionError: connection timed out
|         at Timeout._onTimeout (/home/jorge/Projetos/gira-serve/node_modules/parse-server/node_modules/mongodb/lib/core/sdam/topology.js:437:30)
|         at listOnTimeout (internal/timers.js:557:17)
|         at processTimers (internal/timers.js:500:7) {
|       reason: TopologyDescription {
|         type: 'Single',
|         setName: null,
|         maxSetVersion: null,
|         maxElectionId: null,
|         servers: Map(1) { '127.0.0.1:27017' => [ServerDescription] },
|         stale: false,
|         compatible: true,
|         compatibilityError: null,
|         logicalSessionTimeoutMinutes: null,
|         heartbeatFrequencyMS: 10000,
|         localThresholdMS: 15,
|         commonWireVersion: null
|       }
|     }
 integration-test:
        runs-on: ubuntu-latest
        strategy:
            matrix:
                node-version: [14.x]
                mongodb-version: ['4.4']
        steps:
            - uses: actions/checkout@v2
            - name: Use Node.js 14
              uses: actions/setup-node@v2
              with:
                node-version: 14

            - name: Start MongoDB
              uses: supercharge/mongodb-github-action@1.7.0
              with:
                mongodb-version: 4.4
                mongodb-db: test-database

            - run: npm install -g yarn
            - run: yarn install
            - run: yarn test:integration
              env:
                NODE_ENV: test
                PARSE_SERVER_DATABASE_URI: mongodb://127.0.0.1:27017/test-database?directConnection=true
                DATABASE_NAME: test-database
marcuspoehls commented 2 years ago

@jorgeluisrezende Hey Jorge, can you please share your Node.js code that connects to MongoDB? I’m thinking of connection options could be wrong

jorgeluisrezende commented 2 years ago

@marcuspoehls Im using ParseServer so I'm doing exactly as written in documentation, just instantiating a new ParseServer like..

        this.parseServer = new ParseServer({
            databaseURI: process.env.PARSE_SERVER_DATABASE_URI,
            ...myconfigs,
        });
marcuspoehls commented 2 years ago

@jorgeluisrezende Your connection config looks fine. I can’t tell what your issue is. I remember having connection issues in the past related to server selection timeout errors too. Not sure how I solved them. Maybe you can find details about MongoDB starting properly in your GitHub Actions steps. The logs of each step may show you if something is off

marcuspoehls commented 2 years ago

@jorgeluisrezende Hey Jorge, have you been able to fix the issue?

jorgeluisrezende commented 2 years ago

@marcuspoehls no, I've tested a lot of configs but my workflow still crashing when it tries to connect on mongo, I think its a bug on github runner, i will test it on my own runner to see if it will pass

jorgeluisrezende commented 2 years ago

Thank you for the help!!

marcuspoehls commented 2 years ago

On idea coming to my mind: are you running your code inside a Docker container? Trying to connect from inside a container to MongoDB on localhost:27017 but MongoDB is running inside another Docker container probably having an IP address in 172.x range?

jorgeluisrezende commented 2 years ago

I've tried with both, running inside a container and inside a vm directly, and all tests failed, I even tried to get the container ip and connect on it but again it failed

marcuspoehls commented 2 years ago

OK, thank you for sharing your tries.

aprilahijriyan commented 2 years ago

Hi, I'm experiencing the same thing. Is there any way to fix it?

image

Workflow:

name: Unit testing

on:
  push:
    branches:
      - next
  pull_request:
    branches:
      - next

jobs:
  test_job:
    name: Run tests using python v${{ matrix.py }}
    runs-on: ubuntu-latest
    environment: getpay-api
    strategy:
      fail-fast: false
      matrix:
        py:
          - "3.9"
          - "3.8"

    steps:
      - uses: actions/checkout@v3
      - name: Setup python v${{ matrix.py }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.py }}

      - name: Create environment file
        run: printf '${{secrets.ENV_FILE}}' >> .env

      - name: Export environment variables (app .env)
        uses: cardinalby/export-env-action@1.0.0
        with:
          envFile: .env

      - name: Export environment variables (testing .env)
        uses: cardinalby/export-env-action@1.0.0
        with:
          envFile: .env.testing

      - name: Setup redis
        uses: shogo82148/actions-setup-redis@v1
        with:
          redis-version: latest

      - name: Setup MongoDB
        uses: supercharge/mongodb-github-action@1.7.0
        with:
          mongodb-version: 5.0
          mongodb-username: ${{env.MONGODB_USERNAME}}
          mongodb-password: ${{env.MONGO_PASSWORD}}
          mongodb-db: ${{env.MONGODB_DATABASE}}

      - name: Install dependencies
        run: |
          pip install -r all-requirements.txt

      - name: Initialize data
        run: |
          python3 manage.py init
          python3 manage.py create_user -u ${{env.USER_EMAIL}} -p ${{env.USER_PASSWORD}} -y

      - name: Run tests
        run: |
          pytest -v --cache-clear

The error appears in step Initialize data.

marcuspoehls commented 2 years ago

@aprilahijriyan Hey, can you see MongoDB properly starting in the logs of your GitHub Action?

aprilahijriyan commented 2 years ago

@marcuspoehls looks like i mistyped in mongodb-password: ${{env.MONGO_PASSWORD}} it should be mongodb-password: ${{env.MONGODB_PASSWORD}}.

I'm trying again, and the error appears different.

Here's the error:

pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}
Error: Process completed with exit code 1.

mongodb logs:

/usr/bin/docker run --name cd98fba7a61b654aa4255b909c8acf45ee862_8688e2 --label 4cd98f --workdir /github/workspace --rm -e MONGODB_USERNAME -e MONGODB_PASSWORD -e MONGODB_DATABASE -e Python_DATABASE -e -e MONGODB_USERNAME -e MONGODB_PASSWORD -e MONGODB_DATABASE -e python_ e LD_LIBRARY_PATH -e DEBUG -e USER_EMAIL -e USER_PASSWORD -e INPUT_MONGODB-VERSION -e INPUT_MONGODB-USERNAME -e INPUT_MONGODB*** INPUT_MONGODB-DB -e INPUT_MONGODB-REPLICA-SET HOMEDB -e INPUT -eMONGODB*** GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME - e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e G /e RUNNER_ENV -e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -eCI_E= .sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow": "/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/getpay-api/getpay-api":"/github/ workspace" 4cd98f:ba7a61b654aa4255b909c8acf45ee862 "5" "" "27017" "test_database" "test_user" "test_password"
Starting single-node instance, no replica set
    - ports [27017]
    - version [5]
    - database [test_database]
    - credentials [test_user:test_password]

  Unable to find image 'mongo:5' locally
  5: Pulling from library/mongo
  d7bfe07ed847: Already exists
  97ef66a8492a: Pulling fs layer
  20cec14c8f9e: Pulling fs layer
  38c3018eb09a: Pulling fs layer
  ccc9e1c2556b: Pulling fs layer
  593c62d03532: Pulling fs layer
  1a103a446c3f: Pulling fs layer
  be887b845d3f: Pulling fs layer
  e5543880b183: Pulling fs layer
  ccc9e1c2556b: Waiting
  1a103a446c3f: Waiting
  be887b845d3f: Waiting
  e5543880b183: Waiting
  593c62d03532: Waiting
  97ef66a8492a: Verifying Checksum
  97ef66a8492a: Download complete
  20cec14c8f9e: Verifying Checksum
  20cec14c8f9e: Download complete
  38c3018eb09a: Verifying Checksum
  38c3018eb09a: Download complete
  97ef66a8492a: Pull complete
  593c62d03532: Verifying Checksum
  593c62d03532: Download complete
  ccc9e1c2556b: Verifying Checksum
  ccc9e1c2556b: Download complete
  1a103a446c3f: Verifying Checksum
  1a103a446c3f: Download complete
  e5543880b183: Verifying Checksum
  e5543880b183: Download complete
  20cec14c8f9e: Pull complete
  38c3018eb09a: Pull complete
  ccc9e1c2556b: Pull complete
  593c62d03532: Pull complete
  1a103a446c3f: Pull complete
  be887b845d3f: Verifying Checksum
  be887b845d3f: Download complete
  be887b845d3f: Pull complete
  e5543880b183: Pull complete
  Digest: sha256:37e84d3dd30cdfb5472ec42b8a6b4dc6ca7cacd91ebcfa0410a54528bbc5fa6d
  Status: Downloaded newer image for mongo:5
  ef913e2db664b91c50f43caa3ab2af253d0a36cebbd626c30ee92a622416cc09

The mongodb URL I'm using: mongodb://${{env.MONGODB_USERNAME}}:${{env.MONGODB_PASSWORD}}@localhost:27017/${{env.MONGODB_DATABASE}}

aprilahijriyan commented 2 years ago

Looks like this solution https://stackoverflow.com/a/61703050 solved my problem!

marcuspoehls commented 2 years ago

@aprilahijriyan Hey Aprila, great! Good to know the missing auth source was the issue 👍 thank you for sharing your solution 😃

aprilahijriyan commented 2 years ago

@marcuspoehls I think you should add 'general troubleshooting' in README. I just realized you have mentioned authSource in the commit message. https://github.com/supercharge/mongodb-github-action/commit/ea1a7f385262c1fc4bf653e4ac5822e2f57d44ab