Skip to content

Commit

Permalink
Dont snapshot resolve after reject (#1964)
Browse files Browse the repository at this point in the history
There is a simple issue here in that during an error, resolve() is
called after reject() is called. This is because 'close' is ALWAYS
called no matter what if the stream finishes, or there is an error.

You can verify this if you add console logs to the writer handlers in
the staging branch.
  • Loading branch information
NullSoldier authored Aug 6, 2022
1 parent 9d7bbb0 commit ee9af55
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ironfish-cli/src/commands/chain/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,20 @@ export default class Download extends IronfishCommand {
})

await new Promise<void>((resolve, reject) => {
writer.on('error', (e) => {
const onWriterError = (e: unknown) => {
writer.removeListener('close', onWriterClose)
writer.removeListener('onWriterError', onWriterError)
reject(e)
})
}

writer.on('close', () => {
const onWriterClose = () => {
writer.removeListener('close', onWriterClose)
writer.removeListener('onWriterError', onWriterError)
resolve()
})
}

writer.on('error', onWriterError)
writer.on('close', onWriterClose)

response.data.on('error', (e) => {
writer.destroy(e)
Expand Down

0 comments on commit ee9af55

Please sign in to comment.