From e747c874d81391da324a2d0e3011ec3e9c52eaa9 Mon Sep 17 00:00:00 2001 From: Hugh Cunningham <57735705+hughy@users.noreply.github.com> Date: Fri, 5 Aug 2022 16:59:54 -0700 Subject: [PATCH 1/3] handles 'close' event instead of 'end' event (#1959) WriteStream emits 'close'. 'end' is never emitted, so the download does not resolve at completion. --- ironfish-cli/src/commands/chain/download.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ironfish-cli/src/commands/chain/download.ts b/ironfish-cli/src/commands/chain/download.ts index 7aab906ef1..fadb886db1 100644 --- a/ironfish-cli/src/commands/chain/download.ts +++ b/ironfish-cli/src/commands/chain/download.ts @@ -153,7 +153,7 @@ export default class Download extends IronfishCommand { reject(e) }) - writer.on('end', () => { + writer.on('close', () => { resolve() }) From 9d7bbb0af8e5976731acef1b5d04a28dc82a071a Mon Sep 17 00:00:00 2001 From: Hugh Cunningham <57735705+hughy@users.noreply.github.com> Date: Fri, 5 Aug 2022 20:18:20 -0700 Subject: [PATCH 2/3] bumps the CLI version to 0.1.43 (#1962) --- ironfish-cli/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ironfish-cli/package.json b/ironfish-cli/package.json index 4afc60960b..b94a7d649f 100644 --- a/ironfish-cli/package.json +++ b/ironfish-cli/package.json @@ -1,6 +1,6 @@ { "name": "ironfish", - "version": "0.1.42", + "version": "0.1.43", "description": "CLI for running and interacting with an Iron Fish node", "author": "Iron Fish (https://ironfish.network)", "main": "build/src/index.js", From ee9af55b080c4396f314fa44e61f3c3469860dc4 Mon Sep 17 00:00:00 2001 From: Jason Spafford Date: Sat, 6 Aug 2022 00:03:17 -0400 Subject: [PATCH 3/3] Dont snapshot resolve after reject (#1964) 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. --- ironfish-cli/src/commands/chain/download.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ironfish-cli/src/commands/chain/download.ts b/ironfish-cli/src/commands/chain/download.ts index fadb886db1..d0893082e3 100644 --- a/ironfish-cli/src/commands/chain/download.ts +++ b/ironfish-cli/src/commands/chain/download.ts @@ -149,13 +149,20 @@ export default class Download extends IronfishCommand { }) await new Promise((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)