Skip to content

Concurrency issue on Cache when packrat is enabled. #604

@CarlosDescalziIM

Description

@CarlosDescalziIM

Cache operations get and set are used inside a reentrant lock, but cache clear is called from parse_string outside that reentrant lock.

FifoCache set operation does this:

        def set_(_, key, value):
            cache[key] = value
            while len(cache) > size:
                # pop oldest element in cache by getting the first key
                cache_pop(next(iter(cache)))

That cache_pop(next(iter(cache)) is not thread safe.

Creating a bunch of threads parsing expressions in loop eventually raise a RuntimeError dictionary changed size during iteration
To reproduce it easier put another thread to call ParserElement.reset_cache() in loop

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions