Skip to content

Commit

Permalink
Merge pull request #3907 from bjester/leader-election-fix
Browse files Browse the repository at this point in the history
Reset elector when a duplicate leader is detected and capture errors in Sentry
  • Loading branch information
rtibbles authored Jan 13, 2023
2 parents 15971bb + 4f282bf commit a918204
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions contentcuration/contentcuration/frontend/shared/data/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Dexie from 'dexie';
import * as Sentry from '@sentry/vue';
import mapValues from 'lodash/mapValues';
import channel from './broadcastChannel';
import { CHANGES_TABLE, IGNORED_SOURCE, TABLE_NAMES } from './constants';
Expand Down Expand Up @@ -47,11 +48,25 @@ function runElection() {
elector.awaitLeadership().then(startSyncing);
elector.onduplicate = () => {
stopSyncing();
elector.die().then(runElection);
elector
.die()
.then(() => {
// manually reset reference to dead elector on the channel
// which is set within `createLeaderElection` and whose
// presence is also validated against, requiring its removal
channel._leaderElector = null;
return runElection();
})
.catch(Sentry.captureException);
};
}

export function initializeDB() {
setupSchema();
return db.open().then(runElection);
export async function initializeDB() {
try {
setupSchema();
await db.open();
await runElection();
} catch (e) {
Sentry.captureException(e);
}
}

0 comments on commit a918204

Please sign in to comment.