Skip to content

Commit 09507d3

Browse files
fix(worker): Permission syncer fixes (#624)
1 parent 97dd54d commit 09507d3

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Fixed spurious infinite loads with explore panel, file tree, and file search command. [#617](https://github.com/sourcebot-dev/sourcebot/pull/617)
1515
- Wipe search context on init if entitlement no longer exists [#618](https://github.com/sourcebot-dev/sourcebot/pull/618)
1616
- Fixed Bitbucket repository exclusions not supporting glob patterns. [#620](https://github.com/sourcebot-dev/sourcebot/pull/620)
17+
- Fixed issue where the repo driven permission syncer was attempting to sync public repositories. [#624](https://github.com/sourcebot-dev/sourcebot/pull/624)
18+
- 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)
1719

1820
## [4.9.2] - 2025-11-13
1921

packages/backend/src/ee/accountPermissionSyncer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class AccountPermissionSyncer {
102102
if (this.interval) {
103103
clearInterval(this.interval);
104104
}
105-
await this.worker.close();
105+
await this.worker.close(/* force = */ true);
106106
await this.queue.close();
107107
}
108108

packages/backend/src/ee/repoPermissionSyncer.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,27 @@ export class RepoPermissionSyncer {
5555
const repos = await this.db.repo.findMany({
5656
// Repos need their permissions to be synced against the code host when...
5757
where: {
58-
// They belong to a code host that supports permissions syncing
5958
AND: [
59+
// They are not public. Public repositories are always visible to all users, therefore we don't
60+
// need to explicitly perform permission syncing for them.
61+
// @see: packages/web/src/prisma.ts
62+
{
63+
isPublic: false
64+
},
65+
// They belong to a code host that supports permissions syncing
6066
{
6167
external_codeHostType: {
6268
in: PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES,
6369
}
6470
},
71+
// They have not been synced within the threshold date.
6572
{
6673
OR: [
6774
{ permissionSyncedAt: null },
6875
{ permissionSyncedAt: { lt: thresholdDate } },
6976
],
7077
},
78+
// There aren't any active or recently failed jobs.
7179
{
7280
NOT: {
7381
permissionSyncJobs: {
@@ -106,7 +114,7 @@ export class RepoPermissionSyncer {
106114
if (this.interval) {
107115
clearInterval(this.interval);
108116
}
109-
await this.worker.close();
117+
await this.worker.close(/* force = */ true);
110118
await this.queue.close();
111119
}
112120

packages/backend/src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,35 +111,36 @@ const listenToShutdownSignals = () => {
111111
await redis.quit();
112112
await api.dispose();
113113
await shutdownPosthog();
114-
115114

116115
logger.info('All workers shut down gracefully');
117116
signals.forEach(sig => process.removeListener(sig, cleanup));
117+
return 0;
118118
} catch (error) {
119119
Sentry.captureException(error);
120120
logger.error('Error shutting down worker:', error);
121+
return 1;
121122
}
122123
}
123124

124125
signals.forEach(signal => {
125126
process.on(signal, (err) => {
126-
cleanup(err).finally(() => {
127-
process.kill(process.pid, signal);
127+
cleanup(err).then(code => {
128+
process.exit(code);
128129
});
129130
});
130131
});
131132

132133
// Register handlers for uncaught exceptions and unhandled rejections
133134
process.on('uncaughtException', (err) => {
134135
logger.error(`Uncaught exception: ${err.message}`);
135-
cleanup('uncaughtException').finally(() => {
136+
cleanup('uncaughtException').then(() => {
136137
process.exit(1);
137138
});
138139
});
139140

140141
process.on('unhandledRejection', (reason, promise) => {
141142
logger.error(`Unhandled rejection at: ${promise}, reason: ${reason}`);
142-
cleanup('unhandledRejection').finally(() => {
143+
cleanup('unhandledRejection').then(() => {
143144
process.exit(1);
144145
});
145146
});

0 commit comments

Comments
 (0)