@@ -99,7 +99,7 @@ export async function requestRemoteNode(
9999 // Called if we stall for 30s without receiving any data
100100 const handleTimeout = async ( ) : Promise < void > => {
101101 fsWriteStream . close ( )
102- fs . removeSync ( tmpFilename )
102+ await fs . remove ( tmpFilename )
103103
104104 if ( attempt < STALL_RETRY_LIMIT ) {
105105 // Retry by calling ourself recursively
@@ -151,13 +151,13 @@ export async function requestRemoteNode(
151151
152152 // If there's a 400/500 response or other error.
153153 // it will trigger a finish event on fsWriteStream
154- responseStream . on ( `error` , error => {
154+ responseStream . on ( `error` , async error => {
155155 if ( timeout ) {
156156 clearTimeout ( timeout )
157157 }
158158
159159 fsWriteStream . close ( )
160- fs . removeSync ( tmpFilename )
160+ await fs . remove ( tmpFilename )
161161
162162 if ( ! ( error instanceof RequestError ) ) {
163163 return reject ( error )
@@ -229,14 +229,14 @@ export async function requestRemoteNode(
229229 responseStream . on ( `response` , response => {
230230 resetTimeout ( )
231231
232- fsWriteStream . once ( `finish` , ( ) => {
232+ fsWriteStream . once ( `finish` , async ( ) => {
233233 if ( timeout ) {
234234 clearTimeout ( timeout )
235235 }
236236
237237 // We have an incomplete download
238238 if ( ! haveAllBytesBeenWritten ) {
239- fs . removeSync ( tmpFilename )
239+ await fs . remove ( tmpFilename )
240240
241241 if ( attempt < INCOMPLETE_RETRY_LIMIT ) {
242242 // let's give node time to remove the file
0 commit comments