You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I experienced the same issue as described here - #1413.
TypeError: Cannot perform Construct on a detached ArrayBuffer
at new Uint8Array (<anonymous>)
at new FastBuffer (node:internal/buffer:959:5)
at Buffer.slice (node:buffer:1121:10)
at TLSSocket.onData (file:///D:/www/upload-test/node_modules/node-fetch/src/index.js:407:36)
at TLSSocket.emit (node:events:538:35)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)
constonData=buf=>{console.log(`previousChunk: ${previousChunk&&previousChunk.byteLength}`);console.log(`Buffer: ${buf&&buf.byteLength}`);properLastChunkReceived=Buffer.compare(buf.slice(-5),LAST_CHUNK)===0;// Sometimes final 0-length chunk and end of message code are in separate packetsif(!properLastChunkReceived&&previousChunk){try{properLastChunkReceived=(Buffer.compare(previousChunk.slice(-3),LAST_CHUNK.slice(0,3))===0&&Buffer.compare(buf.slice(-2),LAST_CHUNK.slice(3))===0);}catch(error){console.log(error.message)}}previousChunk=buf;};
The result is:
fixResponseChunkedTransferBadEnding called...
previousChunk: undefined
Buffer: 65536
fixResponseChunkedTransferBadEnding called...
previousChunk: 0
Buffer: 65536
Cannot perform Construct on a detached ArrayBuffer
previousChunk: 0
Buffer: 65536
Cannot perform Construct on a detached ArrayBuffer
previousChunk: 65536
Buffer: 65536
previousChunk: 65536
Buffer: 65536
previousChunk: 65536
Buffer: 65536
previousChunk: 0
Buffer: 65536
Cannot perform Construct on a detached ArrayBuffer
previousChunk: 0
Buffer: 65536
Cannot perform Construct on a detached ArrayBuffer
previousChunk: 0
Buffer: 65536
Cannot perform Construct on a detached ArrayBuffer
previousChunk: 0
Buffer: 65536
Cannot perform Construct on a detached ArrayBuffer
previousChunk: 0
Buffer: 99
Cannot perform Construct on a detached ArrayBuffer
previousChunk: undefined
Buffer: 65536
Looks like previousChunk variable is not holding the actual previous buffer. Notice that previousChunk behavior is not consistent, sometimes it contains the buffer sometimes it's empty. Probably because is set by reference and in the meantime, the buffer is drained in some other place.
Expected behavior
There should be no Cannot perform Construct on a detached ArrayBuffer error.
previousChunk variable from onData function to be reliable should always contain the actual previous buffer.
Potential solution
Modify the following line to copy the buffer instead of passing the reference:
However, if I use form-data package there is no issue. So I'm not entirely sure if the issue is with fetch-node itself, it can be related to how formdata-node handle buffers.
I experienced the same issue as described here - #1413.
Reproduction
I'm using following code to reproduce the error:
I tracked down the issue to the following function:
node-fetch/src/index.js
Lines 395 to 407 in 8ced5b9
I modified the function to add some debugging:
The result is:
Looks like
previousChunk
variable is not holding the actual previous buffer. Notice thatpreviousChunk
behavior is not consistent, sometimes it contains the buffer sometimes it's empty. Probably because is set by reference and in the meantime, the buffer is drained in some other place.Expected behavior
Cannot perform Construct on a detached ArrayBuffer
error.previousChunk
variable fromonData
function to be reliable should always contain the actual previous buffer.Potential solution
Modify the following line to copy the buffer instead of passing the reference:
node-fetch/src/index.js
Line 406 in 8ced5b9
or
The result now:
Your Environment
Additional context
However, if I use
form-data
package there is no issue. So I'm not entirely sure if the issue is withfetch-node
itself, it can be related to howformdata-node
handle buffers.Result:
The text was updated successfully, but these errors were encountered: