Skip to content

Reorder channel selection order and make Stop() idempotent #159

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

Merged
merged 5 commits into from
Mar 27, 2021

Conversation

CHTJonas
Copy link
Member

This PR:

  • Reorders the channels in the main select clause of the Run() function so that we always deal with received packets first rather than sending new packet out. This is so that the TTL values don't go stale when pinging very rapidly (cf. Allow intervals of 0 seconds #154).
  • Improves CPU usage slightly by greedily calling Stop() on tickers where possible.
  • Removes the initial packet sent around line 403 which I can't really see a need for.

@SuperQ
Copy link
Contributor

SuperQ commented Mar 26, 2021

I think I prefer to stick to the defer Stop() method. Having to maintain stops on all function exits is fragile.

@CHTJonas
Copy link
Member Author

How about a single function which makes all the necessary Stop() calls? I could factor this out into a separate PR if necessary (and maybe merge with parts of #116 minus the error bit)?

@SuperQ
Copy link
Contributor

SuperQ commented Mar 26, 2021

It's not the number of function calls, it's the fact that you need to make sure they're all there at any exit from the function. This is why defer is used.

@CHTJonas
Copy link
Member Author

Updated to use the defer-style syntax which I think looks better. It's objectively less code to worry about/forget in that select clause. I've also included the idempotent pinger.Stop() because it made sense to.

Copy link
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

LGTM, nice.

Copy link
Contributor

@mem mem left a comment

Choose a reason for hiding this comment

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

Adding a comment as to why the first p.sendICMP(conn) is necessary.

@CHTJonas CHTJonas changed the title Reorder channels in main select clause Reorder channel selection order and make Stop() idempotent Mar 26, 2021
@CHTJonas
Copy link
Member Author

This also fixes #157.

Copy link
Member

@sparrc sparrc left a comment

Choose a reason for hiding this comment

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

lgtm, just to double-verify this bullet point in the original description does not apply anymore correct?

  • Removes the initial packet sent around line 403 which I can't really see a need for.

IIUC the initial packet send was re-added by 91995fe

@CHTJonas
Copy link
Member Author

Yep correct on all accounts @sparrc!

@CHTJonas CHTJonas force-pushed the chtjonas/run-reorder branch from abe6f7c to afbbb46 Compare March 27, 2021 00:17
@CHTJonas CHTJonas merged commit 80a5113 into master Mar 27, 2021
@CHTJonas CHTJonas deleted the chtjonas/run-reorder branch March 27, 2021 00:20
@chenk008
Copy link

In my opinion, there is no guarantee order in select clause.

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.

5 participants