1
0
Fork 0
mirror of synced 2024-07-01 04:21:06 +12:00

Handle db creation race conditions

This commit is contained in:
adrinr 2023-01-31 16:15:11 +00:00
parent bb43812ac5
commit b2813db5db
3 changed files with 9 additions and 20 deletions

View file

@ -37,19 +37,6 @@ services:
timeout: 20s
retries: 3
couch-init:
image: curlimages/curl
environment:
PUT_CALL: "curl -u ${COUCH_DB_USER}:${COUCH_DB_PASSWORD} -X PUT couchdb-service:5984"
depends_on:
- couchdb-service
command:
[
"sh",
"-c",
"sleep 10 && $${PUT_CALL}/_users && $${PUT_CALL}/_replicator; fg;",
]
redis-service:
restart: on-failure
image: redis

View file

@ -58,7 +58,14 @@ export class DatabaseImpl implements Database {
throw new Error("DB does not exist")
}
if (!exists) {
await DatabaseImpl.nano.db.create(this.name)
try {
await DatabaseImpl.nano.db.create(this.name)
} catch (err: any) {
// Handling race conditions
if (err.statusCode !== 412) {
throw err
}
}
}
return DatabaseImpl.nano.db.use(this.name)
}

View file

@ -22,7 +22,6 @@ import * as redis from "./utilities/redis"
import { events, logging, middleware } from "@budibase/backend-core"
import { initialise as initialiseWebsockets } from "./websocket"
import { startup } from "./startup"
import { retry } from "./utilities/retry"
const Sentry = require("@sentry/node")
const destroyable = require("server-destroy")
@ -81,11 +80,7 @@ server.on("close", async () => {
})
export default server.listen(env.PORT || 0, async () => {
if (!env.isTest()) {
await startup(app, server)
} else {
await retry(async () => await startup(app, server))
}
await startup(app, server)
})
const shutdown = () => {