They implemented trim with a regex? Neither Java nor .NET do that. The postmortem here should probably be "why are you reimplementing trim".
Stack Overflow Outage Postmortem
61–70 of 335 posts
Re: Stack Overflow Outage Postmortem
#62The lesson seems to be "Always run trim() before running regex" and "validate content as much as possible before running regex".
Or just reject this input. The server isn't the time and place to do data cleanup. Can always fix this on the frontend with JavaScript for free if it's an actual problem.
Re: Stack Overflow Outage Postmortem
#63> It took 10 minutes to identify the cause. I'm impressed they were able to do this so quickly.
Re: Stack Overflow Outage Postmortem
#64Re: Stack Overflow Outage Postmortem
#65> It took 10 minutes to identify the cause. I'm impressed they were able to do this so quickly.
System not responsive. Look at the CPU load. Look at the process peaking at 100%. Force dump the stack track of the process couple times. Hmm. All of them stuck in the regex engine. Look back up the stack track to see who calls it. Oh, it's on the home page's text cleansing code. Something like that.
Re: Stack Overflow Outage Postmortem
#66Re: Stack Overflow Outage Postmortem
#67> It took 10 minutes to identify the cause. I'm impressed they were able to do this so quickly.
System not responsive. Look at the CPU load. Look at the process peaking at 100%. Force dump the stack track of the process couple times. Hmm. All of them stuck in the regex engine. Look back up the stack track to see who calls it. Oh, it's on the home page's text cleansing code. Something like that.
Re: Stack Overflow Outage Postmortem
#68Ha! The same bug happened internally at my company. In that case it was a regex matching a URL taking so much CPU as to cause a DOS of a proxy server. I won't be surprised if it's happened to someone here too. This is very timely, because minutes ago, I made a link to Russ Cox's articles in my Kernighan awk repo: https://github.com/andychu/bwk https://swtch.com/~rsc/regexp/regexp1.html If you are not familiar with th…
Re: Stack Overflow Outage Postmortem
#69I think this might have been the post they quoted. http://stackoverflow.com/questions/38484433/in-corona-sdk-ho...
Re: Stack Overflow Outage Postmortem
#70That's not how backtracking works. A regex engine will only backtrack to try and make the rest of the regex match, i.e. it will take characters of the RHS of the string, not try and start "from the second character off the start of the string". I mean, if the engine tried matching from the second space, what would be matching the first space? Something has to.
Which meant, that even if the regex engine was incredibly stupid and could not figure out that a greedy block of \s was never going to contain a non-\s, it would only have to check 20,001 times, not 199000 (or whatever it was).
I can't reproduce this "bug" in either Perl or Python. The time taken to match a 30,000 block of space either followed by $ or XX$ was basically identical for \s+$.
There does appear to be normal backtracking going on, roughly doubling the search time for large strings terminating in non-\s. This is expected, as it has to check 20,000 during the first gobble, then 20,000 as it backtracks from the right 20,000 times.
$ time perl -e '(" " x 100000000 . "X") =~ /\s+$/ && print "MATCH"'
real 0m0.604s
user 0m0.509s
sys 0m0.094s
$ time perl -e '(" " x 100000000) =~ /\s+$/ && print "MATCH"'
MATCH
real 0m0.286s
user 0m0.197s
sys 0m0.089s