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
{{ message }}
Repository navigation
Possible race condition in metadata() when using Stream-based input #3451
const image_path = "./Images/128x128.png"
const test = async() => {
const image1 = sharp(image_path).pipe(sharp())
const image2 = sharp(image_path).pipe(sharp())
const data1 = await image1.metadata()
console.log(data1)
const data2 = await image2.metadata() // on this instruction the node interpreter will exit
console.log(data2)
}
When we await for the metadata of data2 the node interpreter will immediately exit without any error. I tried to debug it but I could not find the point in which the node interpreter is closed (I might assume this happens in native, but I'm not sure).
This issue never happens if we work on different images so the following code is totally fine and works as expected
Thanks for reporting, there was a possible race condition when awaiting metadata() for Stream-based input, especially when the input Stream was very short i.e. smaller images.
Commit df97120 fixes this and adds a test that would previously have failed. This will be included as part of v0.31.3.
changed the title [-]Piping twice the same image to sharp results in a sudden and undesired node exit[/-][+]Possible race condition in metadata() when using Stream-based input[/+]on Nov 13, 2022
Thanks for your answer. Just out of curiosity, why was the interpreter exiting without returning any error? I would have expected some sort of error, even like a segfault, but I was getting nothing in all the environment I tried
The "finish" event was already firing before the listener was attached, so the Promise returned by metadata() was never resolved or rejected.
I assume you invoked your sample by adding a call to test() at the top level rather than await test(). This means that once all other logic in the script had completed, the event loop would have been empty and with no callbacks remaining, the process ended.
Activity
Prevent possible race condition when reading metadata #3451
lovell commentedon Nov 13, 2022
Thanks for reporting, there was a possible race condition when awaiting
metadata()for Stream-based input, especially when the input Stream was very short i.e. smaller images.Commit df97120 fixes this and adds a test that would previously have failed. This will be included as part of v0.31.3.
[-]Piping twice the same image to sharp results in a sudden and undesired node exit[/-][+]Possible race condition in metadata() when using Stream-based input[/+]lucakcustom commentedon Nov 13, 2022
Thanks for your answer. Just out of curiosity, why was the interpreter exiting without returning any error? I would have expected some sort of error, even like a segfault, but I was getting nothing in all the environment I tried
lovell commentedon Nov 13, 2022
The "finish" event was already firing before the listener was attached, so the Promise returned by
metadata()was never resolved or rejected.I assume you invoked your sample by adding a call to
test()at the top level rather thanawait test(). This means that once all other logic in the script had completed, the event loop would have been empty and with no callbacks remaining, the process ended.lucakcustom commentedon Nov 14, 2022
Now I see. Thanks again, I appreciated your answer.
lovell commentedon Dec 21, 2022
v0.31.3 now available, thanks again for reporting.