I have a Telegram bot built with Python and Program, which is deployed on an Azure Web App. Initially, the bot worked fine, but it stopped responding after some time. The Azure Web App logs indicate that the container failed to start within the expected time limit (WEBSITES_CONTAINER_START_TIME_LIMIT). The logs show that the Gunicorn server, running the Flask app, started successfully but encountered timeout errors, terminating the worker process after around 10 minutes. This cycle repeated until the Azure Web App timed out after 30 minutes, indicating that the app wasn't responding to HTTP requests within the configured time limit. Strangely, about 30 minutes after encountering these timeouts, the bot started working again without any changes to the code or configuration.
I added a startup command to the Azure Web App settings to ensure that Gunicorn is properly configured to run the Flask app hosting the Telegram bot. The command I used was:
gunicorn -b 0.0.0.0:8000 app:app
This command specifies the host and port for Gunicorn to listen on (0.0.0.0:8000) and the Flask app instance (app:app).
I also adjusted the environment variables in the Azure Web App settings, setting:
WEBSITES_CONTAINER_START_TIME_LIMIT=1800
WEBSITES_PORT=8080
I expected that by increasing the WEBSITES_CONTAINER_START_TIME_LIMIT value and specifying the WEBSITES_PORT, the bot would have enough time to start up and handle incoming requests without timing out. Additionally, by adding the Gunicorn startup command, I expected the bot to start and run reliably on the Azure Web App without encountering startup timeout errors.
After adding the startup command and environment variables, the logs showed:
2024-05-24T04:54:08.914Z INFO - Waiting for response to warmup request for container telegram-bot-dignified-india_0_1a331a3c. Elapsed time = 1786.2027409 sec
2024-05-24T04:54:23.007Z ERROR - Container telegram-bot for site telegram-bot-dignified-india did not start within expected time limit. Elapsed time = 1800.2955472 sec
2024-05-24T04:54:23.013Z ERROR - Container telegram-bot didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2024-05-24T04:54:23.018Z INFO - Stopping site telegram-bot-dignified-india because it failed during startup.
also wanted to mention that below log repeated multiple times at once.
2024-05-24T04:54:08.914Z INFO - Waiting for response to warmup request for container telegram-bot. Elapsed time = 1786.2027409 sec


