-
Notifications
You must be signed in to change notification settings - Fork 119
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
MarkdownRenderer
is not concurrent safe
#210
Comments
@Fallen-Breath, you are right. If nothing else (we could at least avoid that exception from calling |
Another thing, while having just looked at #212, mistletoe also partly uses class attributes to temporarily store parsed data in between method calls (e.g. here). AFAIK, this could cause random errors when running mistletoe in parallel (within a single Python process), right? So, I think mistletoe as a whole was not written with having thread-safety on mind. Wondering how much of an issue this could be among common mistletoe users...? |
I have a similar problem with this implementation. It's not concurrency but gets into issues when it has two instances of
I wonder if we can have an internal state for each renderer instance. |
Mistletoe's reliance on global state has been annoying me for some time, so I used my unexpected free time to refactor it to explicitly pass state around instead. I tried some tricks to keep compatibility with old token code, but sadly none of them worked well enough, so I had to change a lot of mistletoe's API. A compatibility layer could be created so that existing users of mistletoe could keep their code unchanged, but it wouldn't make their use of mistletoe thread-safe. @pbodnar as the most active maintainer, would you consider merging something like this? A large breaking change to mistletoe's structure to make it concurrent and reentrant, with or without a compatibility layer? Or is the current state good enough and this change too disruptive? |
@dvdkon, thanks for pushing this further. As you yourself write, it is not a small change. So I'm not sure if I can give it the required time nowadays. So far, we've got just 3 upvotes for this issue, which is a relatively small number. But I agree it would be great to have mistletoe thread-safe. I guess I will look at this closer one day, but I cannot promise anything... |
What
Constructing a
MarkdownRenderer
modifies a global array (mistletoe.block_token.remove_token
), which is not concurrent safemistletoe/mistletoe/markdown_renderer.py
Line 112 in b911e5b
As a result, using renderers in multiple threads at the same time results in exception being raised
To reproduce
Reproducable with
mistletoe==1.2.1
It will raise
Other notes
Yeah I'm aware of the following notes in the readme:
If the described issue is an expected behavior, I'll suggest to leave a warning in the readme as well, so people know they need a
threading.Lock
for thisThe text was updated successfully, but these errors were encountered: