Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance is running, but unavailable #9

Open
ilyanesteroff opened this issue Aug 31, 2023 · 2 comments
Open

Instance is running, but unavailable #9

ilyanesteroff opened this issue Aug 31, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@ilyanesteroff
Copy link

ilyanesteroff commented Aug 31, 2023

Hi!
When using dynamodb-action for unit tests on ubuntu-latest with actions, the instance is running, netstat shows something at 8000. But running lsof -i :8000 exits with 1 indicating the instance is unavailable.

netstat log on port 8000:
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN

Here is the workflow file:

name: Deployment
on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]
jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16.x]

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: "npm"

      - name: Start DynamoDB
        uses: rrainn/[email protected]
        with:
          port: 8000
          cors: "*"

      - name: netstat
        run: netstat -l

      - name: Check DynamoDB
        run: lsof -i :8000

      - name: Deps
        run: npm i

      - name: Test
        run: npm run test:ci

      - name: Build
        run: npm run build:ci

The same situation is happening when using amazon/dynamodb-local with services
Here is the config:

name: Deployment
on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]
jobs:
  build:
    runs-on: ubuntu-latest

    services:
      dynamodb:
        image: amazon/dynamodb-local
        ports:
          - 8000:8000

    strategy:
      matrix:
        node-version: [16.x]

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: "npm"

      - name: netstat
        run: netstat -l

      - name: Check DynamoDB
        run: lsof -i :8000

      - name: Deps
        run: npm i

      - name: Test
        run: npm run test:ci

      - name: Build
        run: npm run build:ci

Stuck on this isssue, wondering whether there is a problem with Github-actions, DynamoDB or config, I would appreciate any assistance on this 😅

@fishcharlie
Copy link
Member

I think I'm running into the same issue. I'll try to look into this shortly. Really have no idea what is going on here at first glance. It's strange that running it as a service doesn't work either.

This GitHub Action is pretty simple, so really thinking it's more a result of GitHub Actions as opposed to anything this action is doing wrong.

@fishcharlie fishcharlie added the bug Something isn't working label Sep 14, 2024
@fishcharlie
Copy link
Member

I could not reproduce this in a blank test repository. I have no idea why. But you can see the results and play around with it yourself at: https://github.com/fishcharlie/DynamoDBGHActionTest.

However, this was still an issue for one of my projects. So what I ended up doing is running the following script right after setting up DynamoDB Local:

const { DynamoDBClient, ListTablesCommand } = require('@aws-sdk/client-dynamodb');

const client = new DynamoDBClient({ region: 'us-west-2', endpoint: 'http://localhost:8000', credentials: { accessKeyId: 'fake', secretAccessKey: 'fake' } });

const startTime = new Date().getTime();
const TIMEOUT = 10000; // 10 seconds
async function check() {
	try {
		await client.send(new ListTablesCommand({}));
		console.log("Success. Local DynamoDB is running.");
		process.exit(0);
	} catch (err) {
		if (new Date().getTime() - startTime > TIMEOUT) {
			console.log(`Error: Local DynamoDB is not running after ${TIMEOUT / 1000} seconds. Exiting...`);
			process.exit(1);
		}
		console.log("Error: Local DynamoDB is not running. Waiting for 100 milliseconds and retrying...");
		await timeout(100);
		check();
	}
}
check();

function timeout(ms) {
	return new Promise(resolve => setTimeout(resolve, ms));
}

The logs printed out the following for me:

Error: Local DynamoDB is not running. Waiting for 100 milliseconds and retrying...
Error: Local DynamoDB is not running. Waiting for 100 milliseconds and retrying...
Error: Local DynamoDB is not running. Waiting for 100 milliseconds and retrying...
Error: Local DynamoDB is not running. Waiting for 100 milliseconds and retrying...
Error: Local DynamoDB is not running. Waiting for 100 milliseconds and retrying...
Error: Local DynamoDB is not running. Waiting for 100 milliseconds and retrying...
Success. Local DynamoDB is running.

That ended up running for 3 seconds according to GitHub Actions (maybe there was a long start up time???).

I'm willing to consider adding a flag within this Action to run a similar script automatically. But would like some feedback before I move forward with that. Does the script above solve this problem for anyone else? Would you like to see a flag within this Action to do this automatically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants