-
-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Panic while accessing SleepyTicker methods Stop()/SetSleep()
The time.Ticker object was stored as a value type, but it is expected to be a pointer according to its implementation: ``` func (t *Ticker) Stop() func (t *Ticker) Reset(d Duration) ``` This was leading to an application crash. STR 1: Run `portmaster-core` without privileged rights. It will not be able to start the kernel driver (Windows). During unloading of already initialized modules, the process crashes because of stopping SleepyTicker instances in workers of the "network" module. STR 2: Run tests from `service\mgr\sleepyticker_test.go`
- Loading branch information
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package mgr | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestSleepyTickerStop(t *testing.T) { | ||
normalDuration := 100 * time.Millisecond | ||
sleepDuration := 200 * time.Millisecond | ||
|
||
st := NewSleepyTicker(normalDuration, sleepDuration) | ||
st.Stop() // no panic expected here | ||
} | ||
|
||
func TestSleepyTicker(t *testing.T) { | ||
normalDuration := 100 * time.Millisecond | ||
sleepDuration := 200 * time.Millisecond | ||
|
||
st := NewSleepyTicker(normalDuration, sleepDuration) | ||
|
||
// Test normal mode | ||
select { | ||
case <-st.Wait(): | ||
// Expected tick | ||
case <-time.After(normalDuration + 50*time.Millisecond): | ||
t.Error("expected tick in normal mode") | ||
} | ||
|
||
// Test sleep mode | ||
st.SetSleep(true) | ||
select { | ||
case <-st.Wait(): | ||
// Expected tick | ||
case <-time.After(sleepDuration + 50*time.Millisecond): | ||
t.Error("expected tick in sleep mode") | ||
} | ||
|
||
// Test sleep mode with sleepDuration == 0 | ||
st = NewSleepyTicker(normalDuration, 0) | ||
st.SetSleep(true) | ||
select { | ||
case <-st.Wait(): | ||
t.Error("did not expect tick when sleepDuration is 0") | ||
case <-time.After(normalDuration): | ||
// Expected no tick | ||
} | ||
|
||
// Test stopping the ticker | ||
st.Stop() | ||
select { | ||
case <-st.Wait(): | ||
t.Error("did not expect tick after stopping the ticker") | ||
case <-time.After(normalDuration): | ||
// Expected no tick | ||
} | ||
} |