@@ -167,9 +167,8 @@ export async function run(paths, opts, ctx = {}) {
167167
168168 await sleep ( 150 ) ;
169169
170-
171170 // Wait for FIN/OK from receiver or peer close
172- const finAckTimeoutMs = normalizeTimeout (
171+ const finAckTimeoutMs = normalizeTimeout (
173172 opts ?. finAckTimeoutMs ,
174173 DEFAULT_FIN_ACK_TIMEOUT_MS ,
175174 ) ;
@@ -183,14 +182,19 @@ export async function run(paths, opts, ctx = {}) {
183182 sessionId,
184183 timeoutMs : finAckTimeoutMs ,
185184 } ) ;
185+
186+ let finAckError = null ;
186187 if ( finAckResult === "timeout" && Number . isFinite ( finAckTimeoutMs ) && finAckTimeoutMs > 0 ) {
187- getLogger ( ) . info (
188- `send: timed out waiting for receiver FIN acknowledgement after ${ finAckTimeoutMs } ms` ,
189- ) ;
188+ finAckError = `send: timed out waiting for receiver FIN acknowledgement after ${ finAckTimeoutMs } ms` ;
189+ getLogger ( ) . info ( finAckError ) ;
190190 } else if ( finAckResult === "ack" ) {
191191 getLogger ( ) . debug ( "send: received receiver FIN acknowledgement" ) ;
192192 } else if ( finAckResult === "peer-close" ) {
193- getLogger ( ) . debug ( "send: data channel closed before FIN acknowledgement was observed" ) ;
193+ finAckError = "send: data channel closed before FIN acknowledgement was observed" ;
194+ getLogger ( ) . debug ( finAckError ) ;
195+ } else if ( finAckResult === "nack" ) {
196+ finAckError = "send: receiver reported failure while acknowledging FIN" ;
197+ getLogger ( ) . info ( finAckError ) ;
194198 }
195199
196200 if ( finAckResult !== "peer-close" ) {
@@ -205,6 +209,13 @@ export async function run(paths, opts, ctx = {}) {
205209 ) ;
206210 }
207211 }
212+
213+ if ( finAckError ) {
214+ const err = new Error ( finAckError ) ;
215+ err . code = "ERR_FIN_ACK" ;
216+ throw err ;
217+ }
218+
208219 process . stderr . write ( "\nDone • " + humanBytes ( totalBytes ) + "\n" ) ;
209220 // --- Silent workaround on success
210221 } finally {
@@ -253,8 +264,12 @@ function waitForFinAck({ rtc, sessionId, timeoutMs }) {
253264 } catch { }
254265 }
255266 const fin = msg ? parseStreamFin ( msg ) : null ;
256- if ( fin && fin . sessionId === sessionId && fin . ok === true ) {
257- finish ( "ack" ) ;
267+ if ( fin && fin . sessionId === sessionId ) {
268+ if ( fin . ok === true ) {
269+ finish ( "ack" ) ;
270+ } else if ( fin . ok === false ) {
271+ finish ( "nack" ) ;
272+ }
258273 }
259274 } catch { }
260275 } ) ;
0 commit comments