db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

db-migrate command timing out when called from Docker #814

Open dschinkel opened 1 year ago

dschinkel commented 1 year ago

I'm submitting a...

Current behavior

I am running the following in my Docker Container:

Expected behavior

After container runs my db-migrate command, it's able to connect to the database without timing out.

Dockerfile

...some stuff and then: CMD [ "node_modules/db-migrate/bin/db-migrate", "up:production", "-e", "production" ]

Minimal reproduction of the problem with instructions

When I push my container up to Google Cloud, and Cloud Run tries to run my container, and I get this error in Google Cloud logs when db-migrate is run from my container

2023-04-16 00:14:51.027 CDT
at /app/node_modules/db-migrate/lib/commands/up.js:19:14
2023-04-16 00:14:51.027 CDT
at /app/node_modules/db-migrate/connect.js:17:7
2023-04-16 00:14:51.027 CDT
at /app/node_modules/db-migrate/lib/driver/index.js:95:9
2023-04-16 00:14:51.027 CDT
at Client._connectionCallback (/app/node_modules/db-migrate-pg/index.js:710:7)
2023-04-16 00:14:51.027 CDT
at Client._handleErrorWhileConnecting (/app/node_modules/pg/lib/client.js:318:19)
2023-04-16 00:14:51.027 CDT
at Client._handleErrorEvent (/app/node_modules/pg/lib/client.js:328:19)
2023-04-16 00:14:51.027 CDT
at Connection.emit (node:events:527:28)
2023-04-16 00:14:51.027 CDT
at Socket.reportStreamError (/app/node_modules/pg/lib/connection.js:57:12)
2023-04-16 00:14:51.027 CDT
at Socket.emit (node:events:527:28)
2023-04-16 00:14:51.027 CDT
at emitErrorNT (node:internal/streams/destroy:151:8)
2023-04-16 00:14:51.027 CDT
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
2023-04-16 00:14:51.027 CDT
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2023-04-16 00:14:51.027 CDT
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16)
2023-04-16 00:14:51.089 CDT
Container called exit(1).
2023-04-16 00:14:51.126 CDT
Cloud Runv1database-migrations-00094-quw {@type: type.googleapis.com/google.cloud.audit.AuditLog, methodName: v1, resourceName: namespaces/wedotdd-1349/revisions/database-migrations-00094-quw, response: {…}, serviceName: run.googleapis.com, status: {…}}
2023-04-16 00:14:51.224 CDT
Cloud Runv1database-migrations {@type: type.googleapis.com/google.cloud.audit.AuditLog, methodName: v1, resourceName: namespaces/wedotdd-1349/services/database-migrations, response: {…}, serviceName: run.googleapis.com, status: {…}}
2023-04-16 00:24:18.453 CDT
Cloud RunReplaceServicedatabase-migrationswedotdd-graphql@wedotdd-1349.iam.gserviceaccount.com {@type: type.googleapis.com/google.cloud.audit.AuditLog, authenticationInfo: {…}, authorizationInfo: […], methodName: google.cloud.run.v1.Services.ReplaceService, request: {…}, requestMetadata: {…}, resourceLocation: {…}, resourceName: namespaces/wedotdd-1349/services/database-migrations, response: …
2023-04-16 00:26:36.602 CDT
[ERROR] AssertionError [ERR_ASSERTION]: ifError got unwanted exception: connect ETIMEDOUT XX.XXX.XXX.XXX:5432

(NOTE: I replaced the real IP for the DB with X's for this post to hide it here)

I saw that there was in the past in one of the issues a acquireTimeout database prop the creator of db-migrate suggested but I tried that and I don't see that in the docs so I don't know that it's a thing anymore. If not a thing I'm not sure how to add a timeout for db-migrate.

Environment

db-migrate version: ^0.11.13 plugins with versions: "^1.2.2" db-migrate driver with versions: PostgreSQL 12.12

Additional information:

oleghind commented 1 year ago

Did you find a solution? I can't locate acquireTimeout anywhere in the code

oleghind commented 1 year ago

I think this helped me:

"acquireTimeout": 1000000,
"connectTimeout": 1000000