Skip to content
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

disallow reentrancy #380

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

disallow reentrancy #380

wants to merge 1 commit into from

Conversation

arnetheduck
Copy link
Member

Reentrancy causes event reordering and stack explosions, in addition to leading to hard-to-debug scenarios.

Since none of chronos is actually tested under reentrant conditions (ie that all features such as exceptions, cancellations, buffer operations, timers etc work reliably when the loop is reentered), this is hard to support over time and prevents useful optimizations - this PR simply detects and disallows the behaviour to remove the uncertainty, simplifying reasoning about the event loop in general.

@arnetheduck arnetheduck marked this pull request as draft April 25, 2023 14:35
@arnetheduck
Copy link
Member Author

Marked draft to merge into 4.0

@arnetheduck arnetheduck added the version-4 PR:s intended for an upcoming breaking release label Apr 25, 2023
doAssert not loop.polling, "The event loop and chronos functions in general are not reentrant"

loop.polling = true
defer: loop.polling = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe Chronos already needs to wrap every call to user-land in try/except, so why is it not possible to just set this flag there, just before entering user-land?

Reentrancy causes event reordering and stack explosions, in addition to
leading to hard-to-debug scenarios.

Since none of chronos is actually tested under reentrant conditions (ie
that all features such as exceptions, cancellations, buffer operations,
timers etc work reliably when the loop is reentered), this is hard to
support over time and prevents useful optimizations - this PR simply
detects and disallows the behaviour to remove the uncertainty,
simplifying reasoning about the event loop in general.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
version-4 PR:s intended for an upcoming breaking release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants