From 35649d3ad224272afa6b31510631f290b898a68e Mon Sep 17 00:00:00 2001 From: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:12:24 +0800 Subject: [PATCH] chore(apps/whale-api): add 15 seconds timeout to ModelProbeIndicator.liveness (#1903) #### What this PR does / why we need it: As per the title. Why? Because `this.block.getHighest()` doesn't have a timeout, it can run forever. --- apps/whale-api/src/module.model/_model.probes.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/whale-api/src/module.model/_model.probes.ts b/apps/whale-api/src/module.model/_model.probes.ts index 84afc6bbb4..bff67614c3 100644 --- a/apps/whale-api/src/module.model/_model.probes.ts +++ b/apps/whale-api/src/module.model/_model.probes.ts @@ -19,7 +19,10 @@ export class ModelProbeIndicator extends ProbeIndicator { */ async liveness (): Promise { try { - await this.block.getHighest() + await Promise.race([ + this.block.getHighest(), + new Promise((resolve, reject) => setTimeout(() => reject(new Error('model.timeout')), 15000)) + ]) } catch (err) { return this.withDead('model', 'unable to get the latest block') }