Intermittent Error 500 on First Access – Works After Multiple Refreshes

Hi everyone,

I’m encountering a recurring 500 Internal Server Error when trying to access my web application for the first time after a period of inactivity. The issue consistently occurs on the initial access or after some idle time, but after 2-3 refreshes, the page loads without any issues, and the app works fine moving forward.

Details of the setup:

  • Technology: The web application is built using Flask (Python) and SQLAlchemy.
  • Database: We are connecting to an MS Azure SQL Database.
  • Connection String: Configured with ODBC Driver 18 for SQL Server.
  • Firewall: The firewall is configured correctly and allows access. If it were blocking access, the app wouldn’t work even after multiple refreshes.
  • Driver Version: Using ODBC Driver 18 (most recent version).
  • Link to the application: vCard
  • Issue: On first access or after idle time, there’s a timeout leading to the 500 error, but multiple refreshes eventually establish the connection and allow the application to run.

What we’ve done so far:

  • Verified the connection string.
  • Ensured that firewall rules are allowing the connection.
  • Confirmed the ODBC driver version is up to date.

Has anyone experienced something similar or could point to possible causes for this intermittent behavior?

Thanks for your help!

Hello @Andre_Costa,
Are you using serverless tier for your DB? It looks simiar to another issue from this topic Try updating pool_recycle in you SQLAlchemy config

1 Like