3 ms·
I wouldn't expect people to have to change that setting often, and 1 second seems very reasonable to me. So yes, `Regexp.timeout` is supposed to be a default s
by andreynering 5y ago
I wouldn't expect people to have to change that setting often, and 1 second seems very reasonable to me.
So yes, `Regexp.timeout` is supposed to be a default setting for the app, and when really needed you can override it with the `timeout:` key.
- JohnBooty 5y agoYeah the implementation they've chosen seems totally perfect to me. Sane global default, easily overridable globally or locally. No easy way to override it locally when using =~, but I can't imagine too many cases where you would want to use a local timeout anyway.... can just switch away from =~ syntax for those. This is mostly a denial-of-service mitigation tool, something you'd just want to apply globally to avoid disasters spawned by malformed or malicious input. In practice, it's hard to imagine a use case where you'd really want to be twiddling the knobs on a regexp-by-regexp basis.
- freedomben 5y agoYes good point, I was initially thinking that it would make sense to always ask yourself "how long should this take" and tune appropriately, but for the vast majority of regexes that's overkill, especially if you're not doing anything O(n^2). sticking a 1 second in there gives you a lot of headroom and you can just get more specific for any exceptions.
- JohnBooty 5y agoI was initially thinking that it would make sense to always ask yourself "how long should this take" and tune appropriately, but for the vast majority of regexes that's overkill More than being overkill, it's actually impossible right? The execution time will also vary greatly based on base CPU performance, and current server load. A regexp that takes 10ms to process right now might take 500ms tomorrow when your server is under heavy load. So we can't predict how much time each regexp "needs." But, like you said, we can set a somewhat ridiculously high limit to help prevent regex-based oopsies or re-based DoS attacks from dragging us down =)