From 76a834ca91ca821d7fa1a0fb1794754a9767c8a9 Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Fri, 15 Sep 2023 13:02:38 +0300 Subject: [PATCH] fix: sort toggleNames before updating last seen (#4747) Seems like when 2 pods are trying to POST lastSeen metrics, the db gets into a deadlock state. This is an attempt to fix the deadlock by sorting the toggleNames before the update. The hypothesis is that sorted toggle names will reduce the chance of working on the same row at the same exact time Closes # [1-1382](https://linear.app/unleash/issue/1-1382/order-data-before-updating-the-lastseen-to-reduce-change-of-deadlock) Signed-off-by: andreas-unleash --- src/lib/db/feature-toggle-store.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/db/feature-toggle-store.ts b/src/lib/db/feature-toggle-store.ts index 58dce8b9d7..b8dc6d3af0 100644 --- a/src/lib/db/feature-toggle-store.ts +++ b/src/lib/db/feature-toggle-store.ts @@ -174,7 +174,7 @@ export default class FeatureToggleStore implements IFeatureToggleStore { const environmentArrays = this.mapMetricDataToEnvBuckets(data); try { for (const env of Object.keys(environmentArrays)) { - const toggleNames = environmentArrays[env]; + const toggleNames = environmentArrays[env].sort(); await this.db(FEATURE_ENVIRONMENTS_TABLE) .update({ last_seen_at: now }) .where('environment', env)