nestjs / typeorm

TypeORM module for Nest framework (node.js) 🍇

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typeorm connection error breaks entire nestjs application on boot

alexanderomnix opened this issue · comments

[ ] Regression
[x] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request

Current behavior

I have multiple databases to connect using Nestjs and Typeorm but I wanted my application to started even if the database is unavailable, but I cannot have a workaround how to do it using this module, even after read a lot of issues and the full documentation, how to silence the nestjs Errors and start my application.
Even if the database that I imported at any module level is unavailable the connection still crash the whole stack.

[Nest] 10843   - 09/06/2020 09:17:26   [ExceptionHandler] Failed to connect to localhost:1433 - Could not connect (sequence) +3ms
ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
    at Connection.<anonymous> (/Users/alexander/node/omnix/omnix-admin/backend/node_modules/mssql/lib/tedious/connection-pool.js:68:17)
    at Object.onceWrapper (events.js:422:26)
    at Connection.emit (events.js:315:20)
    at Connection.socketError (/Users/alexander/node/omnix/omnix-admin/backend/node_modules/tedious/lib/connection.js:1290:12)
    at /Users/alexander/node/omnix/omnix-admin/backend/node_modules/tedious/lib/connection.js:1116:21
    at SequentialConnectionStrategy.connect (/Users/alexander/node/omnix/omnix-admin/backend/node_modules/tedious/lib/connector.js:87:14)
    at Socket.onError (/Users/alexander/node/omnix/omnix-admin/backend/node_modules/tedious/lib/connector.js:100:12)
    at Socket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:100:8)
    at emitErrorCloseNT (internal/streams/destroy.js:68:3)

Expected behavior

Application bootstrap even if database is unavailable, and serve modules that do not depend on that connection.

Minimal reproduction of the problem with instructions

Start a simple nestjs project and import the database using TypeOrmModule and the forRoot Method, turn off the database and start the app, the connection breaks the whole application even modules that do not need that connection.

What is the motivation / use case for changing the behavior?

sometimes an application needs to talk to multiple databases that can be on and off, if the connection is unsuccessful I need my app to still on because another modules do not depend on that connection to work.

Environment


Nest version: 7.0.0
 
For Tooling issues:
NPM: 6.14.4
Node:14.1.0
Platform: Mac Os high Sierra 10.13.6
databases: [MSSQL Server 2017, MSSQL Server 2014, MSSQL Server 2014, MSSQL Server 2014]

This issue has been discussed many times in the past. TypeOrmModule won't be a good fit for your case. Please, follow this chapter https://docs.nestjs.com/recipes/sql-typeorm

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.