Skip to content

Retry a rule match once when it spuriously times out - #1501

Open
Sanjays2402 wants to merge 1 commit into
alecthomas:masterfrom
Sanjays2402:fix-retry-timed-out-match
Open

Sanjays2402 wants to merge 1 commit into
alecthomas:masterfrom
Sanjays2402:fix-retry-timed-out-match

Conversation

@Sanjays2402

Copy link
Copy Markdown

Fixes #1498.

Every rule gets a 250ms MatchTimeout, and regexp2 measures it in wall time. A goroutine that waits more than that for a CPU fails its match when it finally runs, even though the match itself only needs microseconds. The token iterator then panics, so highlighting fails at random under load.

Retrying the match once in matchRules fixes it: the goroutine has just been given the CPU, so the retry completes right away. A genuinely runaway pattern still stops, after at most 500ms per rule.

Added TestTokeniseUnderCPUContention, which runs the repro from the issue (64 busy goroutines, GOMAXPROCS(1)). It fails on master with a match timeout error and passes with this change. go test ./... and go vet . are green.

Every rule gets a 250ms MatchTimeout, measured in wall time, so a goroutine starved of CPU can fail a match it would otherwise finish in microseconds. Retrying once in matchRules lets the tokeniser carry on; a genuinely runaway pattern still errors after at most 500ms per rule.

Fixes alecthomas#1498.
@alecthomas

Copy link
Copy Markdown
Owner

Why retry vs. just increasing the timeout?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v3 alpha: Spurious match timeouts under CPU contention panic the lexer

2 participants