-
-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix starting/stopping SPN + more #1668
Changes from all commits
8b6b522
57f08ec
7f0b5ca
78e4a40
113dc04
c6ddaf8
de4cb5b
4b2e4f2
57e81fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package service | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"runtime" | ||
|
||
"github.com/maruel/panicparse/v2/stack" | ||
|
||
"github.com/safing/portmaster/base/utils/debug" | ||
"github.com/safing/portmaster/service/mgr" | ||
) | ||
|
||
// GetWorkerInfo returns the worker info of all running workers. | ||
func (i *Instance) GetWorkerInfo() (*mgr.WorkerInfo, error) { | ||
snapshot, _, err := stack.ScanSnapshot(bytes.NewReader(fullStack()), io.Discard, stack.DefaultOpts()) | ||
if err != nil && !errors.Is(err, io.EOF) { | ||
return nil, fmt.Errorf("get stack: %w", err) | ||
} | ||
|
||
infos := make([]*mgr.WorkerInfo, 0, 32) | ||
for _, m := range i.serviceGroup.Modules() { | ||
wi, _ := m.Manager().WorkerInfo(snapshot) // Does not fail when we provide a snapshot. | ||
infos = append(infos, wi) | ||
} | ||
for _, m := range i.SpnGroup.Modules() { | ||
wi, _ := m.Manager().WorkerInfo(snapshot) // Does not fail when we provide a snapshot. | ||
infos = append(infos, wi) | ||
} | ||
|
||
return mgr.MergeWorkerInfo(infos...), nil | ||
} | ||
Comment on lines
+16
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review: Implementation of This method is similar to the one in Apply the same enhancements regarding error handling and logging as suggested for the |
||
|
||
// AddWorkerInfoToDebugInfo adds the worker info of all running workers to the debug info. | ||
func (i *Instance) AddWorkerInfoToDebugInfo(di *debug.Info) { | ||
info, err := i.GetWorkerInfo() | ||
if err != nil { | ||
di.AddSection( | ||
"Worker Status Failed", | ||
debug.UseCodeSection, | ||
err.Error(), | ||
) | ||
return | ||
} | ||
|
||
di.AddSection( | ||
fmt.Sprintf("Worker Status: %d/%d (%d?)", info.Running, len(info.Workers), info.Missing+info.Other), | ||
debug.UseCodeSection, | ||
info.Format(), | ||
) | ||
} | ||
|
||
func fullStack() []byte { | ||
buf := make([]byte, 8096) | ||
for { | ||
n := runtime.Stack(buf, true) | ||
if n < len(buf) { | ||
return buf[:n] | ||
} | ||
buf = make([]byte, 2*len(buf)) | ||
} | ||
} | ||
Comment on lines
+55
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review: The implementation is identical to that in the Add a comment explaining the buffer resizing strategy as suggested for the |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,33 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
package service | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
"testing" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
"time" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/safing/portmaster/base/notifications" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/safing/portmaster/service/mgr" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
func TestDebug(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
t.Parallel() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
// Create test instance with at least one worker. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
i := &Instance{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
n, err := notifications.New(i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
i.serviceGroup = mgr.NewGroup(n) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
i.SpnGroup = mgr.NewExtendedGroup() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
err = i.Start() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+14
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper cleanup in tests. The test creates an instance and starts it but does not ensure it is properly stopped or cleaned up after the test, which could lead to resource leaks during test runs. Consider adding a + defer i.Stop()
err = i.Start()
if err != nil {
t.Fatal(err)
} Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
time.Sleep(100 * time.Millisecond) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
info, err := i.GetWorkerInfo() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
t.Fatal(err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
t.Log(info) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+11
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using synchronization primitives instead of The use of |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ const ( | |
groupStateInvalid | ||
) | ||
|
||
//nolint:goconst | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider the implications of using The addition of the If the constants are well-defined and used appropriately within the function, this directive is acceptable. However, consider documenting the reason for this suppression to maintain clarity for future maintenance. Consider adding a comment explaining why |
||
func groupStateToString(state int32) string { | ||
switch state { | ||
case groupStateOff: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue: Contradictory linter configuration.
The linters
perfsprint
,testifylint
, andgomoddirectives
are both added and removed. This could be an oversight. Please verify the linter configuration.Also applies to: 27-27, 39-39