You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase Functions无法连接Google Cloud SQL,执行请求超时无返回

Troubleshooting Firebase Functions Timeout with Google Cloud SQL MSSQL

Key Fixes & Debugging Steps

  • Fix Parameterized Query (Eliminate Injection Risk & Silent Failures)
    Your current string interpolation can cause syntax errors (e.g., special characters in userAuthUid) that trigger unreported timeouts. Switch to parameterized queries:

    const mssql = require('mssql');
    const settings = require('../settings.js');
    
    const pool = await mssql.connect(settings.sqlConfig);
    const queryRes = await pool.request()
      .input('userAuthUid', mssql.NVarChar, userAuthUid)
      .input('value', mssql.Int /* Match your SP's parameter type */, value)
      .query('EXEC spUserDelete @userAuthUid, @value');
    
  • Adjust Firebase Function Timeout Limits
    Default timeouts (60s for HTTP functions, 9 mins for background functions) can be hit if your stored procedure runs long. Update firebase.json:

    {
      "functions": {
        "runtimeOptions": {
          "timeoutSeconds": 300 // Max allowed for your function type
        }
      }
    }
    
  • Validate Cloud SQL Connection Health

    • Check the Cloud SQL console for instance outages, maintenance events, or resource constraints.
    • Confirm the Firebase Function's service account has the Cloud SQL Client IAM role.
    • Verify firewall rules/VPC settings haven't changed to block traffic between Functions and SQL.
  • Add Error Logging to Catch Hidden Issues
    Missing error handling hides critical details. Wrap your code in try/catch:

    try {
      const pool = await mssql.connect(settings.sqlConfig);
      const queryRes = await pool.request()
        .input('userAuthUid', mssql.NVarChar, userAuthUid)
        .input('value', mssql.Int, value)
        .query('EXEC spUserDelete @userAuthUid, @value');
      console.log('Query completed:', queryRes);
      return queryRes;
    } catch (err) {
      console.error('Full error:', err);
      throw new Error(`DB operation failed: ${err.message}`);
    } finally {
      await mssql.close();
    }
    
  • Check for Stored Procedure Hangs
    Run spUserDelete directly in your SQL tool with the same parameters to confirm it completes. Look for deadlocks, long-running queries, or locked resources in the SQL Server instance.

内容的提问来源于stack exchange,提问作者Abdelrahman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 23:05:20