-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data corruption due to race condition is possible #3
Comments
Once I have some free time, I will try to make a demo example (should be possible to do with many parallel chunk uploads) |
Thanks a lot for your time @troggy. My way of understanding this is that Might be simple enough to check that. If I find the time for it I'll try to demonstrate what I just said. |
Would be interesting to explore that. I admit I lack some fundamental knowledge on node.js internals here. Btw, the stuff I'm talking about are in
This is a good point. However, the functions don't mutate the object, they create a new one and thus create new pointer. For example this.completedChunks = this.completedChunks.filter(
(uploadedChunk) => uploadedChunk.uploadId !== uploadId,
) will create a new array and |
You're right and as they both use the same JS interpreter I would say that there is no difference at all.
Yeah, you're right my first answer to this point was not relevant then! But I would say the same for the context. |
running the code in production for many months now, the issue didn't happen. Closing |
It is more of a theoretical issue, since I haven't reproduced it yet, but from the code it seems possible.
Many of the functions like
chunkCompleted
orcancelOne
change the state of upload module, e.g. they update state variables likecompletedChunks
andpendingChunkUploads
. Yet these functions could be executed in parallel at the same time (asuploadChunk
function is executed asynchronously for multiple chunks at once). This could corrupt the state of uploadModule.For instance, imagine
chunkCompleted
is called at the same time for two different chunks. Both of them will operate on the samependingChunkUploads
list and they wouldn't know of each other. So the firstchunkCompleted
will remove the completed chunk from the list, but secondchunkCompleted
will remove another completed chunk and keep the one removed by the first call (because, again, they share the exact copies of thependingChunkUploads
list).Described example could lead to the situation when upload won't be marked as complete even when all the chunks are uploaded, because
const isUploadComplete = uploadCompletedChunks.length === upload.partsCount
condition for the very last chunk may return false in this case.Just for your consideration
The text was updated successfully, but these errors were encountered: