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

Nodes the seeder is tracking may not always persist to disk due to races between ThreadDumper and ThreadCrawler #108

Open
cculianu opened this issue Mar 18, 2024 · 0 comments

Comments

@cculianu
Copy link

If ThreadDumper wakes up to save to disk periodically, it may miss nodes that are otherwise good and won't save them to disk. This is because it basically is getting nodes to save to disk from CAddrDb from its two lists: ourId and unkId.

However, when the crawler threads run, they "take" IPs to check from the CAddrDb class. These nodes are temporarily "popped" off the internal lists ourId and/or unkId (only to be returned later once a good/bad result is determined by the crawler).

So if ThreadDumper wakes up while any crawlers are actively checking nodes.. those nodes won't get saved to disk. :'(

melroy89 pushed a commit to BitcoinCash1/Bitcoin-Cash-Node that referenced this issue Oct 10, 2024
The app can now be exited in the usual unix ways (SIGTEM, SIGINT, etc).

The app now fully cleans itself up on exit, and dumps stats to disk
immediately on exit, as opposed to once per hour only (the once per
hour thing still occurs in the background as well, however).

This issue was also something Sipa wanted to fix, see here:
sipa/bitcoin-seeder#76

Note that the extant `ThreadDumper` has an issue when it is saving in
the background: sipa/bitcoin-seeder#108.

A side-effect of this commit is that when the app exits and it does the
final save to disk, no nodes will be lost from the DB, partially
resolving the above issue.

Summary of changes:

- All sleeping in the code (including poll/select) now periodically
  polls the newly-introduced "shutdown requested" flag.
- Added asynch-signal-safe handling of app shutdown signals (SIGINT,
  etc)
- On app signal, set the shutdown requested flag.
- ThreadCrawler socket select/poll now periodically wakes up to check
  the "shutdown requested" flag (this is to allow for fast thread exit
  from the crawler threads).
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

No branches or pull requests

1 participant