Crystal: `parallel` macro leaks fibers

Created on 19 Dec 2018  路  2Comments  路  Source: crystal-lang/crystal

The parallel macro is used to run pieces of code concurrently. Ideally, it waits for all fibers to finish and returns the combined return values of all jobs.

However, when one fiber raises, the exception is raised in the enclosing context which means it will immediately resume execution. This breaks the waiting connection to the other concurrent fibers and send calls to the collector channel block indeterminately. This makes them zombie fibers.

There is no optimal strategy for all use cases, but IMO it would be a better solution to remember the exception but wait for the other fibers to complete and only raise it afterwards. This makes sure that all tasks are properly finished and only raises when execution is to continue in the parent context.

Related to #6468

bug topicconcurrency

Most helpful comment

We introduced parallel just for fun, to see if we could make it work. In my opinion we should remove all these quick features (parallel, future, etc.), rethink them, then reintroduce them.

All 2 comments

We introduced parallel just for fun, to see if we could make it work. In my opinion we should remove all these quick features (parallel, future, etc.), rethink them, then reintroduce them.

Can be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asterite picture asterite  路  3Comments

lgphp picture lgphp  路  3Comments

asterite picture asterite  路  3Comments

relonger picture relonger  路  3Comments

Sija picture Sija  路  3Comments