-
Notifications
You must be signed in to change notification settings - Fork 36.2k
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
Exit bitcoind immediately on shutdown instead of 200ms later #10125
Conversation
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.
utack, no reason to sleep.
src/init.cpp
Outdated
|
||
void StartShutdown() | ||
{ | ||
fRequestShutdown = true; | ||
std::unique_lock<std::mutex> lockShutdownWait(mutexShutdownWait); | ||
cvShutdownWait.notify_all(); |
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.
Should this get mirrored to HandleSIGTERM?
src/init.cpp
Outdated
} | ||
bool ShutdownRequested() | ||
{ | ||
return fRequestShutdown; | ||
} | ||
|
||
void WaitForShutdownRequested() { | ||
std::unique_lock<std::mutex> lockShutdownWait(mutexShutdownWait); | ||
cvShutdownWait.wait(lockShutdownWait, []() { return ShutdownRequested(); }); |
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.
not really worth doing, but you could also wrap this in an initial if (!ShutdownRequested()
so as not to take the lock.
src/init.cpp
Outdated
|
||
void StartShutdown() | ||
{ | ||
fRequestShutdown = true; | ||
std::unique_lock<std::mutex> lockShutdownWait(mutexShutdownWait); | ||
cvShutdownWait.notify_all(); |
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.
Are you sure this is allowed in signal handlers? From what I remember that is the reason for the circuitous polling. If not we need a special path for signals and one for the rest (like AbortNode).
a91883c
to
8d790a8
Compare
Made the wait still wake up every 200ms to address the sigTERM issue. |
The QT part would require something like this (though incomplete): jonasschnelli@4ed60ff |
@jonasschnelli is there a way to do that without adding a new thread? Some kind of signal in addition to the current polling method? |
8d790a8
to
ec49648
Compare
Yes, you could use a signal on the uiInterface that sends a Qt signal, similar to how the other signals for ClientModel work. |
Yes. That would be much better. I'll write a commit soon. |
Great! |
src/init.cpp
Outdated
|
||
void StartShutdown() | ||
{ | ||
fRequestShutdown = true; | ||
std::unique_lock<std::mutex> lockShutdownWait(mutexShutdownWait); |
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.
Should acquire the lock before setting fRequestShutdown?
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.
Could, doesnt matter though because fRequestShutdown is atomic.
Honestly I have no idea why travis is failing here. If you remove the cv notify_all() it works fine, the second you add it back travis hangs and I cannot reproduce the issue locally. |
@@ -125,16 +125,27 @@ static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat"; | |||
|
|||
std::atomic<bool> fRequestShutdown(false); | |||
std::atomic<bool> fDumpMempoolLater(false); | |||
static std::mutex mutexShutdownWait; | |||
static std::condition_variable cvShutdownWait; |
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.
Use a CThreadInterrupt here instead? This is exactly what it's meant to be used for :)
I did a run of travis with the create_cache.py script commented out (so the test_runner script just launches the test cases immediately) and the tests seem to fail intermittently. Travis logs here: https://travis-ci.org/jnewbery/bitcoin/builds/217310887 Failure is:
This reproduces locally for me. Seems like there's a race between bitcoind shutting down and responding to the 'stop' RPC. |
Maybe this Qt approach makes more sense: jonasschnelli@d356512 |
@jonasschnelli cool, thanks. Sadly, in the signal handlers we can't call such a function, so we need to have both polling and a notification. I'll look into that later today.
…On March 31, 2017 11:22:12 PM GMT+02:00, Jonas Schnelli ***@***.***> wrote:
Maybe this Qt approach makes more sense:
jonasschnelli@d356512
|
@TheBlueMatt: if you want to execute the function in the main GUI thread, add another Qt signal and use Q_EMIT (emit it from the uiInterface Signal listener). |
ec49648
to
5638344
Compare
Closing. I spent some time debugging further but dont think its a huge deal to sleep 200ms and it looks annoying to fix, at best. Someone else is welcome to pick this up if they feel so inclined. |
This is especially useful for AbortNode(). I have no idea how to make the equivalent change in bitcoin-qt, maybe @jonasschnelli can add some signal thing for it?