diff --git a/apps/worker/src/jobs/events.incoming-event.ts b/apps/worker/src/jobs/events.incoming-event.ts index 87bc2418..b5f7d314 100644 --- a/apps/worker/src/jobs/events.incoming-event.ts +++ b/apps/worker/src/jobs/events.incoming-event.ts @@ -183,6 +183,10 @@ function getSessionEndWithPriority( return async (args) => { const res = await getSessionEnd(args); + if (count > 10) { + throw new Error('Failed to get session end'); + } + // if we get simultaneous requests we want to avoid race conditions with getting the session end // one of the events will get priority and the other will wait for the first to finish if (res === null && priority === false) { @@ -190,10 +194,6 @@ function getSessionEndWithPriority( return getSessionEndWithPriority(priority, count + 1)(args); } - if (count > 10) { - throw new Error('Failed to get session end'); - } - return res; }; }