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

Notify systemd of ShutdownWaitLength #417

Closed
wants to merge 8 commits into from
Closed

Notify systemd of ShutdownWaitLength #417

wants to merge 8 commits into from

Conversation

Hello71
Copy link
Contributor

@Hello71 Hello71 commented Oct 18, 2018

No description provided.

Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

This code will be easier to read if it uses TOR_USEC_PER_SEC.
It might also be worth adding a comment to explain the extra time.

src/feature/hibernate/hibernate.c Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Oct 24, 2018

Pull Request Test Coverage Report for Build 2792

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2664 unchanged lines in 13 files lost coverage.
  • Overall coverage increased (+0.02%) to 62.053%

Files with Coverage Reduction New Missed Lines %
src/lib/thread/compat_pthreads.c 4 91.78%
src/feature/dirparse/authcert_parse.c 18 68.93%
src/feature/dircache/consdiffmgr.c 63 90.09%
src/feature/dircache/dirserv.c 67 63.96%
src/feature/nodelist/authcert.c 122 28.07%
src/feature/nodelist/nodelist.c 127 61.42%
src/feature/dircache/dircache.c 132 69.83%
src/feature/relay/dns.c 155 17.89%
src/feature/dirparse/ns_parse.c 197 67.97%
src/feature/dirclient/dirclient.c 222 18.44%
Totals Coverage Status
Change from base Build 2687: 0.02%
Covered Lines: 44125
Relevant Lines: 71109

💛 - Coveralls

Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Looks good, needs a few tweaks.

I'm also not sure why tor needs an extra 30 seconds to shut down.

* ShutdownWaitLength to more than that, but use a longer type just in case
*/
sd_notifyf(0, "EXTEND_TIMEOUT_USEC=%" PRIu64,
(uint64_t)(options->ShutdownWaitLength + 30) * TOR_USEC_PER_SEC);
Copy link
Contributor

Choose a reason for hiding this comment

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

ShutdownWaitLength is an int. To avoid (a very unlikely) overflow on addition, use:

Suggested change
(uint64_t)(options->ShutdownWaitLength + 30) * TOR_USEC_PER_SEC);
((uint64_t)(options->ShutdownWaitLength) + 30) * TOR_USEC_PER_SEC);

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure why you are giving tor an extra 30 seconds beyond the shutdown wait length to shut down:
https://www.freedesktop.org/software/systemd/man/systemd.service.html#TimeoutStopSec=

1s or 2s seems like a reasonable time for tor to run its event loop and exit, but 30s might make relay operators think that their device has hung.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it a very conservative number because I don't know how long tor might actually take, and because the default is 90 seconds. In fact, it might make more sense to use 90, because that's the default, and ShutdownWaitLength is a sort of "added time". Also note that systemd won't wait around forever like an idiot; as long as tor actually exits before this time the shutdown process will continue immediately. The only difference is that if tor actually fails to exit for some reason then systemd will wait for 30 seconds longer. Also, this won't do anything with the default configurations for ShutdownWaitLength and DefaultTimeoutStopSec, because tor will tell systemd to wait for 30+30=60 seconds, but systemd will wait min(60, DefaultTimeoutStopSec=90)=90 seconds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For future reference, I think you should've opened two separate comments here (I think that's possible...).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I remember why I increased this from my first revision: I wanted to consider the case where tor may in fact take an extra few tens of seconds to clean up, which is not entirely absurd, like if we try to free memory that was actually swapped out because it was used at startup and then never again.

Copy link
Contributor

Choose a reason for hiding this comment

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

I made it a very conservative number because I don't know how long tor might actually take, and because the default is 90 seconds. In fact, it might make more sense to use 90, because that's the default, and ShutdownWaitLength is a sort of "added time". Also note that systemd won't wait around forever like an idiot; as long as tor actually exits before this time the shutdown process will continue immediately. The only difference is that if tor actually fails to exit for some reason then systemd will wait for 30 seconds longer. Also, this won't do anything with the default configurations for ShutdownWaitLength and DefaultTimeoutStopSec, because tor will tell systemd to wait for 30+30=60 seconds, but systemd will wait min(60, DefaultTimeoutStopSec=90)=90 seconds.

I understand now. Please add a comment that explains the systemd default of 90 seconds.

@@ -0,0 +1,3 @@
o Minor features (relay usability):
- Notify systemd of ShutdownWaitLength so it can be set to more than 90
Copy link
Contributor

Choose a reason for hiding this comment

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

The Tor default is actually 30s:
https://github.com/torproject/tor/blob/master/contrib/dist/tor.service.in

Suggested change
- Notify systemd of ShutdownWaitLength so it can be set to more than 90
- Notify systemd of ShutdownWaitLength so it can be set to more than 30

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but the systemd default is 90.

Copy link
Contributor

Choose a reason for hiding this comment

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

The default in the tor systemd config is 30 seconds. This overrides the systemd default. So on distributions that use the tor systemd config, this patch is required to extend ShutdownWaitLength beyond 30 seconds.

To avoid relay operator confusion, let's use the lower figure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm... to be honest I'm not sure how the default TimeoutSec works. It seems to me like if tor waits 30 seconds, and then does some non-zero work, then it should always be killed by systemd, assuming that systemd is not overly busy.

Hello71 and others added 4 commits October 30, 2018 22:08
@teor2345 teor2345 mentioned this pull request Nov 5, 2018
@Hello71 Hello71 closed this Dec 1, 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.

3 participants