Recognizing Automatic Recovery from a Telegram Network Timeout
How to tell when a Telegram network timeout in Hermes has already recovered on its own.
In short
Hermes looked frozen in Telegram, but the gateway was still running. A short network timeout put Telegram in retrying, and Hermes rebuilt its Telegram adapter (the piece that talks to Telegram) by itself. No restart was required. Wait, recheck, and restart only if it is still failing after the network is back.
What you need
- A shell on the Hermes machine
jqandcurl- About 15 seconds between checks (
sleep 15is the recheck used here)
Check that it is retrying, not stopped
- Read the service, the process, the state file, and the heartbeat:
hermes gateway status
ps -eo pid,ppid,stat,etime,%cpu,%mem,wchan:24,cmd \
| grep -E '[h]ermes_cli.main gateway run|[h]ermes.*gateway'
jq '{gateway_state,active_agents,platforms,updated_at}' \
~/.hermes/gateway_state.json
stat -c '%y %n' ~/.hermes/state/gateway.heartbeat
The process was sleeping normally. It was not in state T (job-control stopped). Hermes reported:
Telegram polling degraded
Telegram network error
telegram-init timed out
rebuilding the adapter
- Test the path to Telegram from this machine:
getent ahostsv4 api.telegram.org
curl -4 -sS -o /dev/null \
-w 'HTTP %{http_code}, connect=%{time_connect}s, total=%{time_total}s\n' \
--connect-timeout 5 \
--max-time 12 \
https://api.telegram.org/
The VM hit a short timeout while polling Telegram. The old updater did not stop before Hermes’s recovery deadline, so Hermes threw it away and built a new adapter.
This was not a dead gateway. The main process stayed up, Hermes kept updating state, the recovery queue stayed active, and the network came back with no action. curl got an HTTP response from api.telegram.org.
After the rebuild, state was gateway_state running, active_agents 0, telegram.state connected, and telegram.error_code null.
Restart only if it stays broken
- Wait and read the state again:
sleep 15
jq '{gateway_state,active_agents,platforms,updated_at}' \
~/.hermes/gateway_state.json
- Restart only if Telegram is still
retryingorerror, the heartbeat time has stopped moving, and thecurltest above succeeds:
hermes gateway restart
Warning: repeated restarts during a real network outage do not fix the route, and they interrupt work the agent is doing. If you restarted once into an outage, wait for curl to succeed before you restart again.
If it doesn’t work
- The process state is
T. That is a suspended gateway, not this timeout. Resume or replace that process before you restart the service. curltohttps://api.telegram.org/fails. The route is still down. Restarting Hermes will not fix it.- State returns to
connectedanderror_codeisnull. Leave it alone. - The heartbeat timestamp is still advancing. Hermes is working. Give the adapter rebuild time to finish.
- Telegram stays in
erroraftercurlsucceeds and the heartbeat has stalled. Then runhermes gateway restartonce.
Official sources
- Telegram Bot API (
api.telegram.orgis the host this check calls)
Spot something wrong or outdated? Leave a comment below. Every comment is reviewed to keep these posts accurate.
By commenting, you agree to our Terms of use and confirm this is your own work. Short quotes are fine with a credit and link. Copied, unsafe, or abusive comments are removed. See something copied? Say so here.