fix(vhd-lib/merge): fix mergeState.currentBlock
Fixes zammad#8794 and zammad#8168
Introduced by 97d94b795
When the concurrency is one (or race condition), `Math.min(...merging)` could be called with `merging` being empty.
This lead to a `NaN` value which, was stored as `null` in the JSON merge state.
This commit is contained in:
parent
d04b93c17e
commit
468250f291
@ -32,6 +32,7 @@
|
||||
- @xen-orchestra/backups patch
|
||||
- @xen-orchestra/mixins patch
|
||||
- vhd-cli minor
|
||||
- vhd-lib patch
|
||||
- xo-web patch
|
||||
- xo-server-auth-saml minor
|
||||
|
||||
|
@ -93,6 +93,13 @@ module.exports.mergeVhd = limitConcurrency(2)(async function merge(
|
||||
try {
|
||||
const mergeStateContent = await parentHandler.readFile(mergeStatePath)
|
||||
mergeState = JSON.parse(mergeStateContent)
|
||||
|
||||
// work-around a bug introduce in 97d94b795
|
||||
//
|
||||
// currentBlock could be `null` due to the JSON.stringify of a `NaN` value
|
||||
if (mergeState.currentBlock === null) {
|
||||
mergeState.currentBlock = 0
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') {
|
||||
warn('problem while checking the merge state', { error })
|
||||
@ -172,6 +179,7 @@ module.exports.mergeVhd = limitConcurrency(2)(async function merge(
|
||||
merging.add(blockId)
|
||||
mergeState.mergedDataSize += await parentVhd.mergeBlock(childVhd, blockId, isResuming)
|
||||
|
||||
mergeState.currentBlock = Math.min(...merging)
|
||||
merging.delete(blockId)
|
||||
|
||||
onProgress({
|
||||
@ -179,7 +187,6 @@ module.exports.mergeVhd = limitConcurrency(2)(async function merge(
|
||||
done: counter + 1,
|
||||
})
|
||||
counter++
|
||||
mergeState.currentBlock = Math.min(...merging)
|
||||
mergeStateWriter(mergeState)
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user