Skip to content

Commit 11f29c9

Browse files
John15321Copilot
andauthored
fix: prevent race conditions by creating new objects for repository configurations (#943)
* fix: prevent race conditions by creating new objects for repository configurations Signed-off-by: Jan Bronicki <janbronicki@microsoft.com> * Update lib/plugins/repository.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Signed-off-by: Jan Bronicki <janbronicki@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 829bc8b commit 11f29c9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/settings.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ ${this.results.reduce((x, y) => {
327327

328328
async updateRepos (repo) {
329329
this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs()
330-
// Keeping this as is instead of doing an object assign as that would cause `Cannot read properties of undefined (reading 'startsWith')` error
331-
// Copilot code review would recoommend using object assign but that would cause the error
330+
// Create a new object to avoid mutating the shared this.config.repository
331+
// This prevents race conditions when multiple repos are processed concurrently via Promise.all
332332
let repoConfig = this.config.repository
333333
if (repoConfig) {
334-
repoConfig = Object.assign(repoConfig, { name: repo.repo, org: repo.owner })
334+
repoConfig = Object.assign({}, repoConfig, { name: repo.repo, org: repo.owner })
335335
}
336336

337337
const subOrgConfig = this.getSubOrgConfig(repo.repo)
@@ -347,7 +347,8 @@ ${this.results.reduce((x, y) => {
347347
if (subOrgConfig) {
348348
let suborgRepoConfig = subOrgConfig.repository
349349
if (suborgRepoConfig) {
350-
suborgRepoConfig = Object.assign(suborgRepoConfig, { name: repo.repo, org: repo.owner })
350+
// Create a new object to avoid mutating the shared subOrgConfig.repository
351+
suborgRepoConfig = Object.assign({}, suborgRepoConfig, { name: repo.repo, org: repo.owner })
351352
repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, suborgRepoConfig)
352353
}
353354
}

0 commit comments

Comments
 (0)