Repository navigation
Description
[REQUIRED] Environment info
firebase-tools: 15.18.0 (also reproduces on 15.17.0)
Platform: macOS (Darwin 25.5.0), Node.js 24.16.0 (also reproduces on 25.8.1)
Cloud SQL instance: Postgres 17.9, IAM auth enabled (cloudsql.iam_authentication=on), public IP
[REQUIRED] Test case
Any project with a deployed Data Connect service backed by Cloud SQL Postgres, deploying via:
firebase deploy --only dataconnect --project <project-id>[REQUIRED] Steps to reproduce
- Have an existing Data Connect service with a Cloud SQL Postgres instance (IAM auth on).
- Run
firebase deploy --only dataconnect --project <project-id>. - Deploy proceeds past connector deployment, reaches the schema-migration step ("Generating SQL schema migrations to be compatible..."), then fails immediately with
Error: An unexpected error has occurred.
[REQUIRED] Expected behavior
Deploy completes successfully; firebase-tools should not surface a connector teardown error as a deploy failure.
[REQUIRED] Actual behavior
--debug stack trace:
[…] Logged in as <iam-user>
[…] > SELECT pg_get_userbyid(nspowner)
FROM pg_namespace
WHERE nspname = 'public';
[…] (query returns in ~13ms)
[…] CloudSQLConnectorError: The connector was closed.
at CloudSQLInstance.close (.../@google-cloud/cloud-sql-connector/dist/cjs/cloud-sql-instance.js:259:32)
at Connector.close (.../@google-cloud/cloud-sql-connector/dist/cjs/connector.js:252:32)
at cleanUpFn (.../firebase-tools/lib/gcp/cloudsql/connect.js:70:19)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async execute (.../firebase-tools/lib/gcp/cloudsql/connect.js:91:5)
at async executeSqlCmdsAsIamUser (.../firebase-tools/lib/gcp/cloudsql/connect.js:98:12)
at async getSchemaMetadata (.../firebase-tools/lib/gcp/cloudsql/permissionsSetup.js:139:31)
at async setupSchemaIfNecessary (.../firebase-tools/lib/dataconnect/schemaMigration.js:31:28)
at async migrateSchema (.../firebase-tools/lib/dataconnect/schemaMigration.js:137:5)
at async default_1 (.../firebase-tools/lib/deploy/dataconnect/release.js:53:9)
Error: An unexpected error has occurred.
Root cause
This is a transitive-dependency regression. firebase-tools declares "@google-cloud/cloud-sql-connector": "^1.3.3", which today resolves to 1.11.0.
In @google-cloud/cloud-sql-connector >= 1.7.0, CloudSQLInstance.close() calls socket.destroy(new CloudSQLConnectorError({ code: 'ERRCLOSED', … })) on every tracked socket. That schedules an 'error' event via process.nextTick. By that time, cleanUpFn in firebase-tools/lib/gcp/cloudsql/connect.js:67-71 has already await-ed pool.end(), and the pg driver has detached its error listeners. When the scheduled 'error' event fires next tick with no listener, Node escalates it to an uncaught exception, which bubbles up through executeSqlCmdsAsIamUser and surfaces as Error: An unexpected error has occurred.
Bisected on the connector with firebase-tools held constant:
@google-cloud/cloud-sql-connector |
result |
|---|---|
| ≤ 1.6.1 | works (Connector.close() calls socket.destroy() with no argument) |
| ≥ 1.7.0 | broken (introduced socket.destroy(new CloudSQLConnectorError(...))) |
Upstream issue already filed and tracking the connector-side fix: GoogleCloudPlatform/cloud-sql-nodejs-connector#576
Workaround
Pin the transitive connector inside the global firebase-tools install:
cd $(npm root -g)/firebase-tools
npm install --no-save @google-cloud/[email protected]After this, firebase deploy --only dataconnect completes normally.
Suggested fix in firebase-tools
Even after #576 is fixed upstream, cleanUpFn should be defensive — a synchronous throw from a teardown step should not be reported as the overall failure of the operation. Two options, either or both:
- Pin the connector until 576 is fixed:
- "@google-cloud/cloud-sql-connector": "^1.3.3", + "@google-cloud/cloud-sql-connector": ">=1.3.3 <1.7.0",
- Wrap cleanup in try/catch in
lib/gcp/cloudsql/connect.js:This is correct regardless of the upstream fix — teardown errors should never mask a successful operation's results.const cleanUpFn = async () => { try { conn.release(); } catch {} try { await pool.end(); } catch {} try { connector.close(); } catch {} };
Activity
aalej commentedon May 25, 2026
Thanks for the detailed report @ghasemel, I really appreciate this! It does look like the error is coming from the
@google-cloud/cloud-sql-connectorlibrary.As you suggested, I think the immediate fix for this would be to pin the version of
@google-cloud/cloud-sql-connector. It might also be a good idea to wrap the clean up in atry/catchso that error during clean up aren't raised as deployment errors.I'll raise this to our engineering team and mark this as reproducible
fredzqm commentedon May 26, 2026
Thanks for the detailed bug report! Created a PR to catch and log those errors more resiliently.
fix: handle cloud-sql-connector unhandled exceptions on close (#10555)
fix: handle cloud-sql-connector unhandled exceptions on close (#10555)