Fix template evaluation timeouts and add retry logic
Some checks failed
Release Drafter / update_release_draft (push) Failing after 4s

- Add 10 second timeout to template evaluation HTTP calls
- Add retry logic that schedules retry after 30 seconds on failure
- Maintains existing error handling while preventing silent failures
- Fixes issue where template errors cause data to stay stale until next WebSocket event
This commit is contained in:
Clawd
2026-02-23 18:01:36 +00:00
parent 51a9aa5cc9
commit 9ba31cbafe

View File

@@ -94,10 +94,42 @@ async function evaluateTemplate(payload) {
this.logger.debug(`Evaluating template for ${payload.template}`);
}
const hass = this.connections[payload.identifier].hass;
const response = await hass.templates.render(payload.template);
return {
identifier: payload.identifier,
render: response
try {
// Wrap template call with timeout
const response = await Promise.race([
hass.templates.render(payload.template),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Template evaluation timeout')), 10000)
)
]);
return {
identifier: payload.identifier,
render: response
};
} catch (err) {
this.logger.error(`Template evaluation failed: ${err.message}`);
// Schedule retry after 30 seconds
setTimeout(() => {
this.logger.info(`Retrying template evaluation for ${payload.identifier}`);
this.evaluateTemplate(payload).then((ret) => {
// Send appropriate notification based on original request type
if (payload.section !== undefined) {
this.sendSocketNotification("SECTION_DISPLAY_RENDERED", {
...ret,
section: payload.section
});
} else {
this.sendSocketNotification("MODULE_DISPLAY_RENDERED", ret);
}
}).catch((retryErr) => {
this.logger.error(`Template evaluation retry also failed: ${retryErr.message}`);
});
}, 30000);
// Re-throw to maintain existing error handling behavior
throw err;
}
}