diff --git a/server/Db.js b/server/Db.js index d836ef79..b6bff04f 100644 --- a/server/Db.js +++ b/server/Db.js @@ -27,17 +27,16 @@ class Db { this.SeriesPath = Path.join(global.ConfigPath, 'series') this.FeedsPath = Path.join(global.ConfigPath, 'feeds') - const staleTime = 1000 * 60 * 2 - this.libraryItemsDb = new njodb.Database(this.LibraryItemsPath, { lockoptions: { stale: staleTime } }) - this.usersDb = new njodb.Database(this.UsersPath, { lockoptions: { stale: staleTime } }) - this.sessionsDb = new njodb.Database(this.SessionsPath, { lockoptions: { stale: staleTime } }) - this.librariesDb = new njodb.Database(this.LibrariesPath, { datastores: 2, lockoptions: { stale: staleTime } }) - this.settingsDb = new njodb.Database(this.SettingsPath, { datastores: 2, lockoptions: { stale: staleTime } }) - this.collectionsDb = new njodb.Database(this.CollectionsPath, { datastores: 2, lockoptions: { stale: staleTime } }) - this.playlistsDb = new njodb.Database(this.PlaylistsPath, { datastores: 2, lockoptions: { stale: staleTime } }) - this.authorsDb = new njodb.Database(this.AuthorsPath, { lockoptions: { stale: staleTime } }) - this.seriesDb = new njodb.Database(this.SeriesPath, { datastores: 2, lockoptions: { stale: staleTime } }) - this.feedsDb = new njodb.Database(this.FeedsPath, { datastores: 2, lockoptions: { stale: staleTime } }) + this.libraryItemsDb = new njodb.Database(this.LibraryItemsPath, this.getNjodbOptions()) + this.usersDb = new njodb.Database(this.UsersPath, this.getNjodbOptions()) + this.sessionsDb = new njodb.Database(this.SessionsPath, this.getNjodbOptions()) + this.librariesDb = new njodb.Database(this.LibrariesPath, this.getNjodbOptions()) + this.settingsDb = new njodb.Database(this.SettingsPath, this.getNjodbOptions()) + this.collectionsDb = new njodb.Database(this.CollectionsPath, this.getNjodbOptions()) + this.playlistsDb = new njodb.Database(this.PlaylistsPath, this.getNjodbOptions()) + this.authorsDb = new njodb.Database(this.AuthorsPath, this.getNjodbOptions()) + this.seriesDb = new njodb.Database(this.SeriesPath, this.getNjodbOptions()) + this.feedsDb = new njodb.Database(this.FeedsPath, this.getNjodbOptions()) this.libraryItems = [] this.users = [] @@ -59,6 +58,21 @@ class Db { return this.users.some(u => u.id === 'root') } + getNjodbOptions() { + return { + lockoptions: { + stale: 1000 * 20, // 20 seconds + update: 2500, + retries: { + retries: 20, + minTimeout: 250, + maxTimeout: 5000, + factor: 1 + } + } + } + } + getEntityDb(entityName) { if (entityName === 'user') return this.usersDb else if (entityName === 'session') return this.sessionsDb @@ -88,17 +102,16 @@ class Db { } reinit() { - const staleTime = 1000 * 60 * 2 - this.libraryItemsDb = new njodb.Database(this.LibraryItemsPath, { lockoptions: { stale: staleTime } }) - this.usersDb = new njodb.Database(this.UsersPath, { lockoptions: { stale: staleTime } }) - this.sessionsDb = new njodb.Database(this.SessionsPath, { lockoptions: { stale: staleTime } }) - this.librariesDb = new njodb.Database(this.LibrariesPath, { datastores: 2, lockoptions: { stale: staleTime } }) - this.settingsDb = new njodb.Database(this.SettingsPath, { datastores: 2, lockoptions: { stale: staleTime } }) - this.collectionsDb = new njodb.Database(this.CollectionsPath, { datastores: 2, lockoptions: { stale: staleTime } }) - this.playlistsDb = new njodb.Database(this.PlaylistsPath, { datastores: 2, lockoptions: { stale: staleTime } }) - this.authorsDb = new njodb.Database(this.AuthorsPath, { lockoptions: { stale: staleTime } }) - this.seriesDb = new njodb.Database(this.SeriesPath, { datastores: 2, lockoptions: { stale: staleTime } }) - this.feedsDb = new njodb.Database(this.FeedsPath, { datastores: 2, lockoptions: { stale: staleTime } }) + this.libraryItemsDb = new njodb.Database(this.LibraryItemsPath, this.getNjodbOptions()) + this.usersDb = new njodb.Database(this.UsersPath, this.getNjodbOptions()) + this.sessionsDb = new njodb.Database(this.SessionsPath, this.getNjodbOptions()) + this.librariesDb = new njodb.Database(this.LibrariesPath, this.getNjodbOptions()) + this.settingsDb = new njodb.Database(this.SettingsPath, this.getNjodbOptions()) + this.collectionsDb = new njodb.Database(this.CollectionsPath, this.getNjodbOptions()) + this.playlistsDb = new njodb.Database(this.PlaylistsPath, this.getNjodbOptions()) + this.authorsDb = new njodb.Database(this.AuthorsPath, this.getNjodbOptions()) + this.seriesDb = new njodb.Database(this.SeriesPath, this.getNjodbOptions()) + this.feedsDb = new njodb.Database(this.FeedsPath, this.getNjodbOptions()) return this.init() } diff --git a/server/libs/properLockfile/lib/lockfile.js b/server/libs/properLockfile/lib/lockfile.js index d981a00c..6e680d3a 100644 --- a/server/libs/properLockfile/lib/lockfile.js +++ b/server/libs/properLockfile/lib/lockfile.js @@ -118,6 +118,7 @@ function updateLock(file, options) { // the lockfile was deleted or we are over the threshold if (err) { if (err.code === 'ENOENT' || isOverThreshold) { + console.error(`lockfile "${file}" compromised. stat code=${err.code}, isOverThreshold=${isOverThreshold}`) return setLockAsCompromised(file, lock, Object.assign(err, { code: 'ECOMPROMISED' })); } @@ -129,6 +130,7 @@ function updateLock(file, options) { const isMtimeOurs = lock.mtime.getTime() === stat.mtime.getTime(); if (!isMtimeOurs) { + console.error(`lockfile "${file}" compromised. mtime is not ours`) return setLockAsCompromised( file, lock, @@ -152,6 +154,7 @@ function updateLock(file, options) { // the lockfile was deleted or we are over the threshold if (err) { if (err.code === 'ENOENT' || isOverThreshold) { + console.error(`lockfile "${file}" compromised. utimes code=${err.code}, isOverThreshold=${isOverThreshold}`) return setLockAsCompromised(file, lock, Object.assign(err, { code: 'ECOMPROMISED' })); }