Skip to content

Commit

Permalink
fix(xo-server/delta NG): dont start export before all targets ready (#…
Browse files Browse the repository at this point in the history
…3427)

Fixes #3424
  • Loading branch information
julien-f committed Sep 20, 2018
1 parent b98b618 commit ea1c3ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,7 @@
- [Backup NG] Don't fail on VMs with empty VBDs (like CDs or floppy disks) (PR [#3410](https://github.com/vatesfr/xen-orchestra/pull/3410))
- [XOA updater] Fix issue where trial request would fail [#3407](https://github.com/vatesfr/xen-orchestra/issues/3407) (PR [#3412](https://github.com/vatesfr/xen-orchestra/pull/3412))
- [Backup NG logs] Fix log's value not being updated in the copy and report button [#3273](https://github.com/vatesfr/xen-orchestra/issues/3273) (PR [#3360](https://github.com/vatesfr/xen-orchestra/pull/3360))
- [Backup NG] Fix issue when *Delete first* was enabled for some of the remotes [#3424](https://github.com/vatesfr/xen-orchestra/issues/3424) (PR [#3427](https://github.com/vatesfr/xen-orchestra/pull/3427))

### Released packages

Expand Down
33 changes: 22 additions & 11 deletions packages/xo-server/src/xo-mixins/backups-ng/index.js
Expand Up @@ -1227,17 +1227,28 @@ export default class BackupNg {
const streams: any = mapValues(
deltaExport.streams,
lazyStream => {
const pStream = lazyStream()
const forks = Array.from({ length: nTargets }, _ => {
const promise = pStream.then(stream => {
const fork: any = stream.pipe(new PassThrough())
fork.task = stream.task
return fork
})
promise.catch(noop) // prevent unhandled rejection
return promise
})
return () => forks.pop()
// wait for all targets to require the stream and then starts
// the real export and create the forks.
const resolves = []
function resolver (resolve) {
resolves.push(resolve)

if (resolves.length === nTargets) {
const pStream = lazyStream()
resolves.forEach(resolve => {
resolve(
pStream.then(stream => {
const fork: any = stream.pipe(new PassThrough())
fork.task = stream.task
return fork
})
)
})
resolves.length = 0
}
}

return () => new Promise(resolver)
}
)
return () => {
Expand Down

0 comments on commit ea1c3ab

Please sign in to comment.