Skip to content

Commit

Permalink
🐛 Lock when updating git repos
Browse files Browse the repository at this point in the history
Fix #1734
  • Loading branch information
SPGoding committed Feb 20, 2025
1 parent 0b2b3a1 commit 3cfe460
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/web-api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"start": "./bin/server.js"
},
"dependencies": {
"async-mutex": "^0.5.0",
"chalk": "^5.4.1",
"cors": "^2.8.5",
"express": "^5.0.1",
Expand Down
14 changes: 10 additions & 4 deletions packages/web-api-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Mutex } from 'async-mutex'
import chalk from 'chalk'
import cors from 'cors'
import express from 'express'
import { slowDown } from 'express-slow-down'
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
import {
assertRootDir,
cheapRateLimiter,
Expand All @@ -23,6 +24,7 @@ const { hookSecret, port, rootDir } = loadConfig()
await assertRootDir(rootDir)
const gits = await initGitRepos(rootDir)
const cache = new MemCache(gits.mcmeta)
const gitMutex = new Mutex()

const versionRoute = express.Router({ mergeParams: true })
.use(getVersionValidator(cache))
Expand Down Expand Up @@ -111,9 +113,13 @@ const app = express()
repository: { name: string }
}
const git = gits[name === 'vanilla-mcdoc' ? 'mcdoc' : 'mcmeta']
console.info(chalk.yellow(`Updating ${name}...`))
await git.remote(['update', '--prune'])
console.info(chalk.green(`Updated ${name}`))

await gitMutex.runExclusive(async () => {
console.info(chalk.yellow(`Updating ${name}...`))
await git.remote(['update', '--prune'])
cache.invalidate()
console.info(chalk.green(`Updated ${name}`))
})
},
)
.get('/favicon.ico', cheapRateLimiter, (_req, res) => {
Expand Down

0 comments on commit 3cfe460

Please sign in to comment.