Skip to content
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 panic when doing Ctrl-C in the middle of a attack #26

Merged

Conversation

brenol
Copy link
Contributor

@brenol brenol commented Oct 1, 2020

this should fix #23.

As the Attack method is now sending messages to the 'metricsCh', and it looks at the Context being complete (completely stopping the attack), I simply removed the channel send that was being done to metricsCh in gui/keybinds.go . This fixed the panic and the Ctrl-C issue for me.

@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2020

Codecov Report

Merging #26 into master will not change coverage.
The diff coverage is 50.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #26   +/-   ##
=======================================
  Coverage   77.59%   77.59%           
=======================================
  Files           7        7           
  Lines         281      281           
=======================================
  Hits          218      218           
  Misses         45       45           
  Partials       18       18           
Impacted Files Coverage Δ
gui/keybinds.go 41.18% <0.00%> (+2.29%) ⬆️
attacker/attacker.go 71.43% <66.67%> (-2.10%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d51dac...95a3d3f. Read the comment docs.

@@ -95,7 +95,4 @@ func Attack(ctx context.Context, target string, resCh chan *Result, metricsCh ch
}
}
metrics.Close()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To show metrics that cannot be measured until the attack is completed, we'd better send after closing metrics.

Suggested change
metrics.Close()
metrics.Close()
metricsCh <- newMetrics(&metrics)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That actually makes a lot of sense. Will get to work on it

@nakabonne
Copy link
Owner

The root problem can be solved by removing the close(d.metricsCh) at gui/drawer.go:106, so could you get rid of that? (unit tests will fail, but not a problem for now)

@nakabonne
Copy link
Owner

@brenol Thanks for your contribution! It's a great help with multiple issues. Let me just make one thing clear. Your commit and your Github account don't seem to be tied to each other:
image

I'd like to welcome you as a contributor, but as it stands, you don't count as a contributor. Would it be possible to authenticate the Github account on your local PC?

@brenol
Copy link
Contributor Author

brenol commented Oct 2, 2020

@brenol Thanks for your contribution! It's a great help with multiple issues. Let me just make one thing clear. Your commit and your Github account don't seem to be tied to each other:
image

I'd like to welcome you as a contributor, but as it stands, you don't count as a contributor. Would it be possible to authenticate the Github account on your local PC?

Sure, I'll. I knew removing the close() would fix the issue (and it was the first thing I did) but I did it right when I started navigating through the codebase, so I wasn't sure if it would be actually correct.

I'll get that github thingie fixed asap too.

@brenol
Copy link
Contributor Author

brenol commented Oct 2, 2020

Flaky test is hard. Thought I could fix it as-is but I wasn't unable to >sadface< .

I have pushed what I believe is a middleground, but it just feels wrong.

If you don't have any problem with the test that is failing, I'll undo the middleground.

@@ -88,6 +88,8 @@ func Attack(ctx context.Context, target string, resCh chan *Result, metricsCh ch
select {
case <-ctx.Done():
opts.Attacker.Stop()
// metricsCh is already closed (as context is done) so we shouldn't send any metric
return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea! no problem to give back the function when the context expired.

gui/drawer.go Outdated
@@ -103,6 +103,7 @@ End: %v`
)

func (d *drawer) redrawMetrics(ctx context.Context) {
defer close(d.metricsCh)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, we want to get rid of it. But let us leave it as is for once.

@nakabonne
Copy link
Owner

@brenol Thank you for taking the time to solve the problem! LTGM so let me merge this once Github account stuff solved.

@brenol
Copy link
Contributor Author

brenol commented Oct 2, 2020

Still not solved? Thought I was able to solve it (set .gitconfig e-mail to my no-reply e-mail; seems I'm still missing something)

@brenol brenol force-pushed the fix-panic-when-stopping-infinite-attack branch from ea607f7 to 95a3d3f Compare October 2, 2020 05:13
@brenol
Copy link
Contributor Author

brenol commented Oct 2, 2020

Now it's correct, right? Sorry for the force push, easiest way to fix it :)

Copy link
Owner

@nakabonne nakabonne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way to go! helped a lot!

@nakabonne nakabonne merged commit d334ef0 into nakabonne:master Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic when stopping infinite attack
3 participants