From 7db65d5243becb694f64cf2bab3d7d82a3a570c6 Mon Sep 17 00:00:00 2001 From: bkellam Date: Wed, 19 Nov 2025 21:58:09 -0800 Subject: [PATCH 1/3] fix --- packages/backend/src/ee/accountPermissionSyncer.ts | 2 +- packages/backend/src/ee/repoPermissionSyncer.ts | 11 +++++++++-- packages/backend/src/index.ts | 11 ++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/ee/accountPermissionSyncer.ts b/packages/backend/src/ee/accountPermissionSyncer.ts index 81a1a135..a1c879a2 100644 --- a/packages/backend/src/ee/accountPermissionSyncer.ts +++ b/packages/backend/src/ee/accountPermissionSyncer.ts @@ -102,7 +102,7 @@ export class AccountPermissionSyncer { if (this.interval) { clearInterval(this.interval); } - await this.worker.close(); + await this.worker.close(/* force = */ true); await this.queue.close(); } diff --git a/packages/backend/src/ee/repoPermissionSyncer.ts b/packages/backend/src/ee/repoPermissionSyncer.ts index d48f510e..064281ea 100644 --- a/packages/backend/src/ee/repoPermissionSyncer.ts +++ b/packages/backend/src/ee/repoPermissionSyncer.ts @@ -55,19 +55,26 @@ export class RepoPermissionSyncer { const repos = await this.db.repo.findMany({ // Repos need their permissions to be synced against the code host when... where: { - // They belong to a code host that supports permissions syncing AND: [ + // They are not public, as they are always visible to all users. + // @see: packages/web/src/prisma.ts + { + isPublic: false + }, + // They belong to a code host that supports permissions syncing { external_codeHostType: { in: PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES, } }, + // They have not been synced within the threshold date. { OR: [ { permissionSyncedAt: null }, { permissionSyncedAt: { lt: thresholdDate } }, ], }, + // There aren't any active or recently failed jobs. { NOT: { permissionSyncJobs: { @@ -106,7 +113,7 @@ export class RepoPermissionSyncer { if (this.interval) { clearInterval(this.interval); } - await this.worker.close(); + await this.worker.close(/* force = */ true); await this.queue.close(); } diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index c3674834..6ae36163 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -111,20 +111,21 @@ const listenToShutdownSignals = () => { await redis.quit(); await api.dispose(); await shutdownPosthog(); - logger.info('All workers shut down gracefully'); signals.forEach(sig => process.removeListener(sig, cleanup)); + return 0; } catch (error) { Sentry.captureException(error); logger.error('Error shutting down worker:', error); + return 1; } } signals.forEach(signal => { process.on(signal, (err) => { - cleanup(err).finally(() => { - process.kill(process.pid, signal); + cleanup(err).then(code => { + process.exit(code); }); }); }); @@ -132,14 +133,14 @@ const listenToShutdownSignals = () => { // Register handlers for uncaught exceptions and unhandled rejections process.on('uncaughtException', (err) => { logger.error(`Uncaught exception: ${err.message}`); - cleanup('uncaughtException').finally(() => { + cleanup('uncaughtException').then(() => { process.exit(1); }); }); process.on('unhandledRejection', (reason, promise) => { logger.error(`Unhandled rejection at: ${promise}, reason: ${reason}`); - cleanup('unhandledRejection').finally(() => { + cleanup('unhandledRejection').then(() => { process.exit(1); }); }); From 85fb357ed33aa1a8ad34a6791f6e31ad453472be Mon Sep 17 00:00:00 2001 From: bkellam Date: Wed, 19 Nov 2025 22:02:28 -0800 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d939995c..8ff4757a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed spurious infinite loads with explore panel, file tree, and file search command. [#617](https://github.com/sourcebot-dev/sourcebot/pull/617) - Wipe search context on init if entitlement no longer exists [#618](https://github.com/sourcebot-dev/sourcebot/pull/618) - Fixed Bitbucket repository exclusions not supporting glob patterns. [#620](https://github.com/sourcebot-dev/sourcebot/pull/620) +- Fixed issue where the repo driven permission syncer was attempting to sync public repositories. [#624](https://github.com/sourcebot-dev/sourcebot/pull/624) +- Fixed issue where worker would not shutdown while a permission sync job (repo or user) was in progress. [#624](https://github.com/sourcebot-dev/sourcebot/pull/624) ## [4.9.2] - 2025-11-13 From 092212de53500f9b7fc74b16e5fd8f0160f64edc Mon Sep 17 00:00:00 2001 From: bkellam Date: Wed, 19 Nov 2025 22:14:03 -0800 Subject: [PATCH 3/3] improve comment --- packages/backend/src/ee/repoPermissionSyncer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/ee/repoPermissionSyncer.ts b/packages/backend/src/ee/repoPermissionSyncer.ts index 064281ea..802da032 100644 --- a/packages/backend/src/ee/repoPermissionSyncer.ts +++ b/packages/backend/src/ee/repoPermissionSyncer.ts @@ -56,7 +56,8 @@ export class RepoPermissionSyncer { // Repos need their permissions to be synced against the code host when... where: { AND: [ - // They are not public, as they are always visible to all users. + // They are not public. Public repositories are always visible to all users, therefore we don't + // need to explicitly perform permission syncing for them. // @see: packages/web/src/prisma.ts { isPublic: false