Handle db creation race conditions
This commit is contained in:
parent
bb43812ac5
commit
b2813db5db
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 = () => {
|
||||
|
|
Loading…
Reference in New Issue