RubenVerborgh / AsyncIterator

An asynchronous iterator library for advanced object pipelines in JavaScript
https://rubenverborgh.github.io/AsyncIterator/docs/
Other
49 stars 7 forks source link

Fix slow async sources not being destroyed #84

Closed rubensworks closed 2 years ago

rubensworks commented 2 years ago

When a TransformIterator receives an async callback as input, but the callback is very slow, race conditions could occur when destroying the iterator. Concretely, when the iterator was closed/destroy before the callback resolves, the underlying iterator would never be destroyed.

FYI, this caused major problems in the context with link traversal, where the query would end, but underlying link traversal iterators (which can be infinite) kept on running.

This fix should also be taken into account when #83 is being fixed.

RubenVerborgh commented 2 years ago

Oops that's very worrying. Thanks, let me have a look.

RubenVerborgh commented 2 years ago

Note for v4.0: we should avoid needing to update this in multiple places.

RubenVerborgh commented 2 years ago

@rubensworks Counter-proposal at 87006a5ad23ad77ec860bb0142dfe5c623aeb043

The problem was broader: other aspects of setting a source on a closed iterator were also inconsistent with the behavior on open iterators (such as checking whether the source is valid).

rubensworks commented 2 years ago

@RubenVerborgh Looks good to me! Just tested it on my end, and everything still seems to work with the new fix.

RubenVerborgh commented 2 years ago

Great, published as v3.6.2!

rubensworks commented 2 years ago

Thanks!