Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Sometimes PegDownProcessor.markdownToHtml(...) does nothing #53

martinschayna opened this Issue · 4 comments

2 participants


I have this simple utility class with ThreadLocal static field:

public class MarkDownProcessor {
    private static final ThreadLocal<PegDownProcessor> PROCESSOR = 
        new ThreadLocal<PegDownProcessor>() {
            protected PegDownProcessor initialValue() {
                return new PegDownProcessor(Extensions.WIKILINKS + Extensions.AUTOLINKS);

    public static PegDownProcessor get() {
        return PROCESSOR.get();

When I want to render markdown text to page, I can use this:


But from time to time first call to markdownToHtml() renders same output as I passed into. Next call is OK. Maybe, it is a timing stuff. Can I use ThreadLocal for managing instances of PegDownProcessor or it is a bug?


Interesting... I currently can't see any reason why your ThreadLocal construct wouldn't work.
Are you sure you are not caching the instance you get from MarkDownProcessor.get() and somehow access it concurrently from multiple threads?


I'm posting some findings.

  • I don't cache instances of PegDownProcessor
  • it seems that this bug(?) depends on current machine speed, with faster CPU it is more frequent, for example on my dev machine it is very rarely but on production much powerfull server allways
  • it only occurred on first line of markdown source

This is real example:

Not available yet.
Not available yet.  

HTML looks like this:

<p>##Description##<br>Not available yet. </p><h2>Properties</h2><p>Not available yet. </p>

but should be (and after page refresh it is):

<h2>Description</h2><p>Not available yet. </p><h2>Properties</h2><p>Not available yet. </p>

thanks a lot for your deeper analysis.
From the looks of it it really should be a race condition, either in pegdown itself or in the underlying parboiled parser implementation.
I now should have enough to be able to nail this thing down and get it fixed.

Thanks for the report!


Unfortunately I cannot reproduce the issue.
Please distill a small test case that I could use for reproducing...
Closing for the time being.

@sirthias sirthias closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.