-
Notifications
You must be signed in to change notification settings - Fork 201
fix: pass golangci-lint 2.11+ checks #307
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -76,18 +76,17 @@ func (n *corruptCommand) Run(ctx context.Context, random bool) error { | |
| // run netem corrupt command for selected containers | ||
| var wg sync.WaitGroup | ||
| errs := make([]error, len(containers)) | ||
| cancels := make([]context.CancelFunc, len(containers)) | ||
|
|
||
| //nolint:dupl | ||
| for i, c := range containers { | ||
| log.WithFields(log.Fields{ | ||
| "container": c, | ||
| }).Debug("adding network random packet corrupt for container") | ||
| netemCtx, cancel := context.WithTimeout(ctx, n.duration) | ||
| cancels[i] = cancel | ||
| wg.Add(1) | ||
| go func(i int, c *container.Container) { | ||
| defer wg.Done() | ||
| defer cancel() | ||
|
Comment on lines
85
to
+89
Owner
Author
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. This is incorrect. All these files use The old |
||
| errs[i] = runNetem(netemCtx, n.client, c, n.iface, netemCmd, n.ips, n.sports, n.dports, n.duration, n.image, n.pull, n.dryRun) | ||
| if errs[i] != nil { | ||
| log.WithError(errs[i]).Warn("failed to set packet corrupt for container") | ||
|
|
@@ -98,13 +97,6 @@ func (n *corruptCommand) Run(ctx context.Context, random bool) error { | |
| // Wait for all netem commands to complete | ||
| wg.Wait() | ||
|
|
||
| // cancel context to avoid leaks | ||
| defer func() { | ||
| for _, cancel := range cancels { | ||
| cancel() | ||
| } | ||
| }() | ||
|
|
||
| // scan through all errors in goroutines | ||
| for _, err = range errs { | ||
| // take first reported error | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,16 +102,15 @@ func (n *delayCommand) Run(ctx context.Context, random bool) error { | |
| // run netem delay command for selected containers | ||
| var wg sync.WaitGroup | ||
| errs := make([]error, len(containers)) | ||
| cancels := make([]context.CancelFunc, len(containers)) | ||
| for i, c := range containers { | ||
| log.WithFields(log.Fields{ | ||
| "container": c, | ||
| }).Debug("adding network delay for container") | ||
| netemCtx, cancel := context.WithCancel(ctx) | ||
| cancels[i] = cancel | ||
| wg.Add(1) | ||
| go func(i int, c *container.Container) { | ||
| defer wg.Done() | ||
| defer cancel() | ||
|
Comment on lines
109
to
+113
Owner
Author
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. This is incorrect. All these files use The old |
||
| errs[i] = runNetem(netemCtx, n.client, c, n.iface, netemCmd, n.ips, n.sports, n.dports, n.duration, n.image, n.pull, n.dryRun) | ||
| if errs[i] != nil { | ||
| log.WithError(errs[i]).Warn("failed to delay network for container") | ||
|
|
@@ -122,13 +121,6 @@ func (n *delayCommand) Run(ctx context.Context, random bool) error { | |
| // Wait for all netem delay commands to complete | ||
| wg.Wait() | ||
|
|
||
| // cancel context to avoid leaks | ||
| defer func() { | ||
| for _, cancel := range cancels { | ||
| cancel() | ||
| } | ||
| }() | ||
|
|
||
| // scan through all errors in goroutines | ||
| for _, err := range errs { | ||
| // take first found error | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,18 +80,17 @@ func (n *duplicateCommand) Run(ctx context.Context, random bool) error { | |
| // run netem duplicate command for selected containers | ||
| var wg sync.WaitGroup | ||
| errs := make([]error, len(containers)) | ||
| cancels := make([]context.CancelFunc, len(containers)) | ||
|
|
||
| //nolint:dupl | ||
| for i, c := range containers { | ||
| log.WithFields(log.Fields{ | ||
| "container": c, | ||
| }).Debug("adding network random packet duplicates for container") | ||
| netemCtx, cancel := context.WithTimeout(ctx, n.duration) | ||
| cancels[i] = cancel | ||
| wg.Add(1) | ||
| go func(i int, c *container.Container) { | ||
| defer wg.Done() | ||
| defer cancel() | ||
|
Comment on lines
89
to
+93
Owner
Author
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. This is incorrect. All these files use The old |
||
| errs[i] = runNetem(netemCtx, n.client, c, n.iface, netemCmd, n.ips, n.sports, n.dports, n.duration, n.image, n.pull, n.dryRun) | ||
| if errs[i] != nil { | ||
| log.WithError(errs[i]).Warn("failed to set packet duplicates for container") | ||
|
|
@@ -102,13 +101,6 @@ func (n *duplicateCommand) Run(ctx context.Context, random bool) error { | |
| // Wait for all netem commands to complete | ||
| wg.Wait() | ||
|
|
||
| // cancel context to avoid leaks | ||
| defer func() { | ||
| for _, cancel := range cancels { | ||
| cancel() | ||
| } | ||
| }() | ||
|
|
||
| // scan through all errors in goroutines | ||
| for _, err = range errs { | ||
| // take first found error | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,16 +77,15 @@ func (n *lossCommand) Run(ctx context.Context, random bool) error { | |
| // run netem loss command for selected containers | ||
| var wg sync.WaitGroup | ||
| errs := make([]error, len(containers)) | ||
| cancels := make([]context.CancelFunc, len(containers)) | ||
| for i, c := range containers { | ||
| log.WithFields(log.Fields{ | ||
| "container": *c, | ||
| }).Debug("adding network random packet loss for container") | ||
| netemCtx, cancel := context.WithTimeout(ctx, n.duration) | ||
| cancels[i] = cancel | ||
| wg.Add(1) | ||
| go func(i int, c *container.Container) { | ||
| defer wg.Done() | ||
| defer cancel() | ||
|
Comment on lines
84
to
+88
Owner
Author
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. This is incorrect. All these files use The old |
||
| errs[i] = runNetem(netemCtx, n.client, c, n.iface, netemCmd, n.ips, n.sports, n.dports, n.duration, n.image, n.pull, n.dryRun) | ||
| if errs[i] != nil { | ||
| log.WithError(errs[i]).Warn("failed to set packet loss for container") | ||
|
|
@@ -97,13 +96,6 @@ func (n *lossCommand) Run(ctx context.Context, random bool) error { | |
| // Wait for all netem delay commands to complete | ||
| wg.Wait() | ||
|
|
||
| // cancel context to avoid leaks | ||
| defer func() { | ||
| for _, cancel := range cancels { | ||
| cancel() | ||
| } | ||
| }() | ||
|
|
||
| // scan through all errors in goroutines | ||
| for _, err = range errs { | ||
| // take first found error | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,18 +92,17 @@ func (n *lossGECommand) Run(ctx context.Context, random bool) error { | |
| // run netem loss command for selected containers | ||
| var wg sync.WaitGroup | ||
| errs := make([]error, len(containers)) | ||
| cancels := make([]context.CancelFunc, len(containers)) | ||
|
|
||
| //nolint:dupl | ||
| for i, c := range containers { | ||
| log.WithFields(log.Fields{ | ||
| "container": c, | ||
| }).Debug("adding network random packet loss for container") | ||
| netemCtx, cancel := context.WithTimeout(ctx, n.duration) | ||
| cancels[i] = cancel | ||
| wg.Add(1) | ||
| go func(i int, c *container.Container) { | ||
| defer wg.Done() | ||
| defer cancel() | ||
|
Comment on lines
101
to
+105
Owner
Author
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. This is incorrect. All these files use The old |
||
| errs[i] = runNetem(netemCtx, n.client, c, n.iface, netemCmd, n.ips, n.sports, n.dports, n.duration, n.image, n.pull, n.dryRun) | ||
| if errs[i] != nil { | ||
| log.WithError(errs[i]).Warn("failed to set packet loss for container") | ||
|
|
@@ -114,13 +113,6 @@ func (n *lossGECommand) Run(ctx context.Context, random bool) error { | |
| // Wait for all netem delay commands to complete | ||
| wg.Wait() | ||
|
|
||
| // cancel context to avoid leaks | ||
| defer func() { | ||
| for _, cancel := range cancels { | ||
| cancel() | ||
| } | ||
| }() | ||
|
|
||
| // scan through all errors in goroutines | ||
| for _, err := range errs { | ||
| // take first found error | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,18 +100,17 @@ func (n *lossStateCommand) Run(ctx context.Context, random bool) error { | |
| // run netem loss command for selected containers | ||
| var wg sync.WaitGroup | ||
| errs := make([]error, len(containers)) | ||
| cancels := make([]context.CancelFunc, len(containers)) | ||
|
|
||
| //nolint:dupl | ||
| for i, c := range containers { | ||
| log.WithFields(log.Fields{ | ||
| "container": c, | ||
| }).Debug("adding network 4-state packet loss for container") | ||
| netemCtx, cancel := context.WithTimeout(ctx, n.duration) | ||
| cancels[i] = cancel | ||
| wg.Add(1) | ||
| go func(i int, c *container.Container) { | ||
| defer wg.Done() | ||
| defer cancel() | ||
|
Comment on lines
109
to
+113
Owner
Author
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. This is incorrect. All these files use The old |
||
| errs[i] = runNetem(netemCtx, n.client, c, n.iface, netemCmd, n.ips, n.sports, n.dports, n.duration, n.image, n.pull, n.dryRun) | ||
| if errs[i] != nil { | ||
| log.WithError(errs[i]).Warn("failed to set packet loss for container") | ||
|
|
@@ -122,13 +121,6 @@ func (n *lossStateCommand) Run(ctx context.Context, random bool) error { | |
| // Wait for all netem delay commands to complete | ||
| wg.Wait() | ||
|
|
||
| // cancel context to avoid leaks | ||
| defer func() { | ||
| for _, cancel := range cancels { | ||
| cancel() | ||
| } | ||
| }() | ||
|
|
||
| // scan through all errors in goroutines | ||
| for _, err = range errs { | ||
| // take first found error | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,17 +105,16 @@ func (n *rateCommand) Run(ctx context.Context, random bool) error { | |
| // run netem loss command for selected containers | ||
| var wg sync.WaitGroup | ||
| errs := make([]error, len(containers)) | ||
| cancels := make([]context.CancelFunc, len(containers)) | ||
| for i, c := range containers { | ||
| log.WithFields(log.Fields{ | ||
| "container": c, | ||
| "command": netemCmd, | ||
| }).Debug("setting network rate for container") | ||
| netemCtx, cancel := context.WithTimeout(ctx, n.duration) | ||
| cancels[i] = cancel | ||
| wg.Add(1) | ||
| go func(i int, c *container.Container) { | ||
| defer wg.Done() | ||
| defer cancel() | ||
|
Comment on lines
113
to
+117
Owner
Author
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. This is incorrect. All these files use The old |
||
| errs[i] = runNetem(netemCtx, n.client, c, n.iface, netemCmd, n.ips, n.sports, n.dports, n.duration, n.image, n.pull, n.dryRun) | ||
| if errs[i] != nil { | ||
| log.WithError(errs[i]).Warn("failed to set network rate for container") | ||
|
|
@@ -126,13 +125,6 @@ func (n *rateCommand) Run(ctx context.Context, random bool) error { | |
| // Wait for all netem delay commands to complete | ||
| wg.Wait() | ||
|
|
||
| // cancel context to avoid leaks | ||
| defer func() { | ||
| for _, cancel := range cancels { | ||
| cancel() | ||
| } | ||
| }() | ||
|
|
||
| // scan through all errors in goroutines | ||
| for _, err = range errs { | ||
| // take first found error | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package util //nolint:revive // existing package name, renaming is out of scope | ||
| package util | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
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.
This is incorrect. All these files use
:=(short variable declaration), not=(assignment). In Go,:=inside aforloop body creates new block-scoped variables per iteration — each goroutine closure captures its own distinctnetemCtx/cancel(oriptCtx/cancel). There is no sharing across iterations.The old
iptables/loss.gocode did have this bug (it usedctx, cancel = ...with=), which this PR fixes by switching toiptCtx, cancel := ...with:=.See: https://go.dev/doc/faq#closures_and_goroutines