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

Worker restarts: address already in use #54

Open
tiberiu89 opened this issue Jun 10, 2024 · 2 comments
Open

Worker restarts: address already in use #54

tiberiu89 opened this issue Jun 10, 2024 · 2 comments

Comments

@tiberiu89
Copy link

Everything starts fine on the first run, but when changing code and hot reloading is triggered, the worker seems to gracefully shutdown successfully, but upon restarting, the process complains the default 3000 port is already in use(I assume the one nestjs is listening. Now, I have a feeling this is because the worker is spawned as a child process, and it tries to bind to the same address. Maybe I'm wrong, but I can't seem to find a workaround. Any ideas would be appreciated.

@gaizeror
Copy link

it seems like you are missing app.enableShutdownHooks()

async function bootstrap() {
    const port = 3000

    const app = await NestFactory.create(AppModule, {
        bufferLogs: true,
        autoFlushLogs: true,
    })
    app.enableShutdownHooks()

    await app.listen(port, () => {
        /* eslint-disable no-console */
        console.log(`[server]: Server is running at http://localhost:${port}`)
    })
}

bootstrap().catch(err => {
    /* eslint-disable no-console */
    console.error(err)
    process.exit(1)
})

@tiberiu89
Copy link
Author

Apart from a warn saying worker was not cleanly shutdown, this seems to be doing the job. An alternative I used so far is what I described here temporalio/sdk-typescript#1437
basically, running the codebase in 2 processes, one regular http app and the worker running in an application context only, which might adhere better to docker best practices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants