regex icon indicating copy to clipboard operation
regex copied to clipboard

borrow_mut panic in src/dfa.rs:454:31 - DFA cache not thread-safe?

Open hamamo opened this issue 2 years ago • 1 comments

What version of regex are you using?

regex-1.5.4

Describe the bug at a high level.

An application that I'm developing using tokio as async runtime occasionally shows a panic:

thread 'tokio-runtime-worker' panicked at 'already borrowed: BorrowMutError', /home/hmm/.cargo/registry/src/github.com-1ecc6299db9ec823/regex-1.5.4/src/dfa.rs:454:31

What are the steps to reproduce the behavior?

Don't know how to reproduce reliably - it's most likely a race condition with a regex that I put into a lazy_static variable to avoid recompiling the expression all the time. I assume that in some situations tokio might schedule async tasks on different threads, and when one thread wants to borrow the cache mutably while another one already has it this error could occur.

What is the actual behavior?

Panic as described.

What is the expected behavior?

Well, no panic of course :-)

hamamo avatar Feb 26 '22 12:02 hamamo

The cache itself isn't thread safe. There is higher level synchronization that should prevent the same cache from being used in two different threads simultaneously.

Unfortunately, I'm not sure I'll be able to make much progress on this without some kind of reproduction. Could you try to come up with one?

BurntSushi avatar Feb 26 '22 13:02 BurntSushi

Without a reproduction or other details, there really isn't anything actionable here unfortunately. Happy to re-open this if someone can add more data.

BurntSushi avatar Mar 06 '23 15:03 BurntSushi