Comments (6)
I’m definitely open to ideas. In concept the issue we had was that the overhead in tracking running/completed regexs was higher than the overhead of just letting the goroutine stick around and wake up and check for a timeout.
For production scenarios this trade off is worth it, but unit tests are obviously different. Maybe I could add an opt-in package mode for unit testing that changes the timeout tracking behavior to shutdown faster (and consume more resources). It wouldn’t work for benchmarks, but I suspect that’s ok.
from regexp2.
Hi @Emyrk thanks for the ticket. Are you seeing multiple goroutines being created for timeouts? Or just the one maintenance goroutine?
If you use timeouts the design has a single ongoing goroutine to maintain the timeouts. That goroutine should exist for the longest timeout set by the user (even if the regex finishes before the timeout). I don’t consider that a leak because the resources are fixed and knowable up front. However, if you’re seeing something different then that’s a definitely a problem I want to fix.
from regexp2.
I am only seeing the 1 go routine.
The issue I have, is that we are using a highlighting lib called Chroma. We have been using it for awhile. This this new go routine, our unit tests fail because we use https://github.com/uber-go/goleak which requires all go routines to be exited at the end of the unit tests.
Unfortunately I have no control over Chroma, which uses regexp2. So I am unable to make sure this go routine is exited at the end of the unit test.
I recognize the benefit of this feature, and just wanted to start a conversation if this can be resolved in a clean way.
from regexp2.
Yea, I'm internally struggling with what approach to take. In production, I have no issue with this.
A package mode is an interesting idea. It is unfortunate we'd have to call something in our unit tests, and it wouldn't be transparent. As in, you have to catch the leak, look into why, find this toggle.
Is it possible to know "no more matches are in progress"? And if it is a matter of the wakeup time, could that be configurable? Then it can be used for unit tests, but also just a package setting.
package stuff_test
import "github.com/dlclark/regexp2"
func init() {
// Pass in some custom "wake up" check time? Rather than default 100ms?
regexp2.SetClockSleep(time.Millisecond)
}
from regexp2.
Ok, so I've coded up a possible solution here. Before I publish it I figure I'd get validation this would fix your issue.
I assume you have one or more unit tests that have defer goleak.VerifyNone(t)
at the top. In those tests you would add a defer regexp2.StopTimeoutClock()
and it'll make sure the timeout goroutine is done before it returns.
This will likely add ~100ms to each test that does this. If that time is too long then you could also add an init function to set the timeout period to 1ms:
func init() {
//speed up testing by making the timeout clock 1ms
regexp2.SetTimeoutCheckPeriod(time.Millisecond)
}
Thoughts?
from regexp2.
I am pretty sure that will work!
Goleak is to be run on TestMain(m *testing.M)
, so we only need to put this in that one spot. This means the StopTimeoutClock
will be called when all unit tests in the package are complete, and no other code will interact with that clock until the next unit test package starts.
Appreciate you hearing this out.
from regexp2.
Related Issues (20)
- \Z not work on regexp2.RE2 mode HOT 1
- Compatibility issue with NKo Digits HOT 2
- Error while trying to match a string with a specific unicode against a RegExp that contains a space and a group HOT 3
- A bug when .* in the content to match HOT 1
- bugs in scenarios of Chinese characters or incorrect using of match.Index HOT 2
- Is it possible to get the name of the currently matched group? HOT 2
- ecmascript: cannot include class \s in character range
- error parsing regexp: unrecognized grouping construct: (?-1 HOT 1
- Support for Python-style named backreference
- Panic on 32bit architectures HOT 12
- Why the replacement interface for []rune is not supported HOT 1
- Force timeout for testing? HOT 3
- The matching results of strings containing Chinese characters are incorrect HOT 2
- No support for \p{unicode char class} that is supported by the Go stdlib regex package HOT 2
- No support for full unicode that is supported by the ECMAScript regex HOT 1
- xeger functionality HOT 1
- Question: Does this library support "categories" HOT 1
- Match loop cause high CPU usage HOT 2
- TestDeadline fails with go 1.21.3 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from regexp2.