feat(fs/Local#lock): attempt to reacquire in case of compromission
Related to zammad#8826
This commit is contained in:
parent
a963878af5
commit
4bed4195ac
@ -7,7 +7,7 @@ import { fromEvent, retry } from 'promise-toolbox'
|
|||||||
|
|
||||||
import RemoteHandlerAbstract from './abstract'
|
import RemoteHandlerAbstract from './abstract'
|
||||||
|
|
||||||
const { warn } = createLogger('xo:fs:local')
|
const { info, warn } = createLogger('xo:fs:local')
|
||||||
|
|
||||||
// save current stack trace and add it to any rejected error
|
// save current stack trace and add it to any rejected error
|
||||||
//
|
//
|
||||||
@ -110,11 +110,21 @@ export default class LocalHandler extends RemoteHandlerAbstract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _lock(path) {
|
async _lock(path) {
|
||||||
const release = lockfile.lock(this._getFilePath(path), {
|
let release
|
||||||
onCompromised: async error => {
|
const acquire = lockfile.lock.bind(undefined, this._getFilePath(path), {
|
||||||
|
async onCompromised(error) {
|
||||||
warn('lock compromised', { error })
|
warn('lock compromised', { error })
|
||||||
|
try {
|
||||||
|
release = await acquire()
|
||||||
|
info('compromised lock was reacquired')
|
||||||
|
} catch (error) {
|
||||||
|
warn('compromised lock could not be reacquired', { error })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await acquire()
|
||||||
|
|
||||||
return async () => {
|
return async () => {
|
||||||
try {
|
try {
|
||||||
await release()
|
await release()
|
||||||
|
Loading…
Reference in New Issue
Block a user