In our production environment, the CPU of one of our nodes spiked to 100% almost 3 hours. The only way to stop the issue was rebooting the server. We analyzed the process dump we took during the problem. It pointed us to a regular expression called inside the Spire.Doc code. Here are the details:
- Code: Select all
Thread 26 - System ID 11720
Entry point clr!Thread::intermediateThreadProc
Create time 10/28/2022 12:52:50 PM
Time spent in user mode 0 Days 02:52:37.359
Time spent in kernel mode 0 Days 00:00:09.609
This thread is using regular expressions
RegEx Match String : regular sized html document
RegEx Pattern : (?:(?:[^{}]+)?)*\{\s*\}
.NET Call Stack
System.Text.RegularExpressions.RegexInterpreter.Go()+2e94
System.Text.RegularExpressions.RegexRunner.Scan(System.Text.RegularExpressions.Regex, System.String, Int32, Int32, Int32, Int32, Boolean, System.TimeSpan)+185
System.Text.RegularExpressions.Regex.Run(Boolean, Int32, System.String, Int32, Int32, Int32)+1cb
System.Text.RegularExpressions.Regex.Match(System.String, Int32)+30
System.Text.RegularExpressions.RegexReplacement.Replace(System.Text.RegularExpressions.Regex, System.String, Int32, Int32)+61
System.Text.RegularExpressions.Regex.Replace(System.String, System.String)+36
System.Text.RegularExpressions.Regex.Replace(System.String, System.String, System.String)+66
spr᧒.ᜄ(System.String)+167
spr≕.ᜀ(Spire.Doc.Interface.IBody, System.String, Int32, Int32)+ab0
Spire.Doc.Body.ᜀ(System.String, Int32, Int32, Int32)+69
Spire.Doc.Document.ᜀ(System.IO.TextReader, Spire.Doc.Documents.XHTMLValidationType, Int32)+ae
Spire.Doc.Document.ᜀ(System.IO.Stream, Spire.Doc.Documents.XHTMLValidationType)+8d
Spire.Doc.Document.LoadFromStream(System.IO.Stream, Spire.Doc.FileFormat, Spire.Doc.Documents.XHTMLValidationType)+4d
We tested the regular expression
- Code: Select all
(?:(?:[^{}]+)?)*\{\s*\}
Catastrophic backtracking has been detected and the execution of your expression has been halted.
That expression is not coming from our code. Is that something generated from the document? At this point we are trying to understand what triggered the issue and how do we prevented it.