17:07 | <Debadree Chatterjee> | * hello to all the members here! hope you are doing well! i had a question in regards to the implementation of https://github.com/whatwg/streams/commit/007d729f1476f7f1ea34731ba9bd2becb702117e for nodejs I am encountering a case of what seems like a race conditions between promises this can better explained with an example consider this following code: const { TransformStream } = require('stream/web'); const assert = require('node:assert/strict'); (async () => { let controller; const ts = new TransformStream({ start(c) { controller = c; } }); const cancelReason = { name: 'cancelReason' }; const cancelPromise = ts.readable.cancel(cancelReason); controller.terminate(); return Promise.all([ cancelPromise, assert.rejects(ts.writable.getWriter().closed) ]); })(); |
17:22 | <Debadree Chatterjee> | Hello everyone! hope you are doing well! I had one question in regards to the implementation of https://github.com/whatwg/streams/commit/007d729f1476f7f1ea34731ba9bd2becb702117e, i have been trying to implement this in nodejs and i am bumping into what seems like a race condition between promises its better explained with code consider the code here https://gist.github.com/debadree25/c54931a99e493baaf9314a903cd52e12 now when we create a transform stream we have one promise created on the writable side the "startPromise" as noted in https://streams.spec.whatwg.org/#set-up-writable-stream-default-controller and when we called the cancel method on the readable we get a cancellation promise as noted in https://streams.spec.whatwg.org/#transform-stream-default-source-cancel now in the code after this we call on controller.terminate which causes the writable side to go into the "erroring" stage, now comes the interesting part the "startPromise" gets resolved and causes the writable part to go into "errored" mode after which the close promise resolves rejecting the cancellation promise we received I think this is expected behaviour? since promises are executed in a queue manner? strangely this issue doesnt seem to affect the reference implementation here https://github.com/whatwg/streams and the promises get executed in the order: -created start promise -cancel promise created -cancel promise resolving -start promise resolving. I dont think this could be a problem with the spec maybe there is something i am missing? if anyone has any insight it would be great!! Thank you for reading! :-) |