Skip to content

Conversation

@Diapolo
Copy link

@Diapolo Diapolo commented Jun 11, 2012

This pull is based on a discussion with @TheBlueMatt and @laanwj.

  • introduce a new StartShutdown() function, which starts a thread with Shutdown() if no GUI is used and calls uiInterface.QueueShutdown() if a GUI is used
  • all direct uiInterface.QueueShutdown() calls are replaced with StartShutdown() - this ensures a clean GUI shutdown, even when catching a SIGTERM and allows the BitcoinGUI destructor to get called (which fixes a tray-icon issue and keeps the tray-icon until Bitcoin-Qt exits)

The current implementation (current master branch) sometimes crashes Bitcoin-Qt (bad) and doesn't allow GUI object destructors do their work as we call exit() in Shutdown(), which leads to an unremoved tray-icon (as visible bug).

I'm sure we could remove some #include "ui_interface.h" in the modified files, but I was not really sure about that, so input is welcome.

Fixes: #1182

@laanwj
Copy link
Member

laanwj commented Jun 11, 2012

I appreciate that you're trying to improve the naming, but be careful that this does change behaviour in the case of bitcoind.

Previously, QueueShutdown (in non-ui context) started Shutdown in a new thread, to make sure that execution returns immediately. This means that an RPC command such as "quit" got the chance to return a reply. It now calls Shutdown directly, which shuts down bitcoin in the current thread and then exit()s.

src/init.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

I don't like the name "FinishShutdown" much. This is not finishing the shutdown, it is the only real shutdown functionality, the other functions are just queuing it to happen.

Copy link
Author

Choose a reason for hiding this comment

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

If we call Shutdown() Start- or InitShutdown() this can be Shutdown() again, which would be fine then.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's much more clear

@Diapolo
Copy link
Author

Diapolo commented Jun 11, 2012

@laanwj Updated to reflect your suggestions. Can you explain, why noui.cpp is not added in bitcoin-qt.pro? I found it quite strange to not be able to edit that file directly somehow.

@laanwj
Copy link
Member

laanwj commented Jun 11, 2012

Looks good now.

Well, it used to be that noui.cpp conflicted with some functions in the UI. If this is no longer the case due to using boost::signals now, it could be added in bitcoin-qt.pro too... (or otherwise you could add it under "other" files)

@Diapolo
Copy link
Author

Diapolo commented Jun 11, 2012

Fine and at least on my local build it compiles just fine with noui.cpp added to the .pro. Could you verify, if this would break the official Gitian build process before I update the pull?

@laanwj
Copy link
Member

laanwj commented Jun 11, 2012

I'm unable to test gitian right now.

Maybe it's better to leave that for another (more trivial) pull. Focus this one on shutdown functionality, this is quite a big fish to fry, and needs heavy testing.

@Diapolo
Copy link
Author

Diapolo commented Jun 11, 2012

Okay, so let's see what other devs think.

@laanwj
Copy link
Member

laanwj commented Jun 11, 2012

BTW, does this solve the original issue with exit() in Shutdown? I don't see it in the diff.

src/init.cpp Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the previous change do not compile.

Copy link
Author

Choose a reason for hiding this comment

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

Ah I missed that, because it's in an #ifdef, which my compiler ignores, because I compile the GUI version. It should be a Shutdown(NULL).

@TheBlueMatt
Copy link
Contributor

If the one non-compiling change is reverted, ACK

@Diapolo
Copy link
Author

Diapolo commented Jun 11, 2012

I'm asking myself, if the change in net.cpp is correct, but as net.cpp is used by the Qt version and bitcoind it should be a StartShutdown() call.

@TheBlueMatt I reverted the changes that don't compile, they now use Shutdown(NULL); again, which should be fine for a non Qt version.

@laanwj The exit() call in Shutdown() is not an issue anymore for the Qt version, as Shutdown() was moved down (see: https://github.com/bitcoin/bitcoin/pull/1439/files#L6R304) to ensure e.g. BitcoinGUI destructor get's called and objects are not just "killed".

@TheBlueMatt
Copy link
Contributor

ACK

@Diapolo
Copy link
Author

Diapolo commented Jun 11, 2012

@TheBlueMatt One last thing that bothers me, should the 2 Shutdown(NULL); calls in init.cpp be converted to StartShutdown();, which could be considered the default function to call, when a shutdown is needed. It would end up with Shutdown() via a thread, but fits better to the rest of the shutdown code and usage.

@TheBlueMatt
Copy link
Contributor

No, in those two cases, shutdown needs to happen immediately, so launching a shutdown thread instead could cause errors.

@Diapolo
Copy link
Author

Diapolo commented Jun 11, 2012

Understood, thanks :).

@laanwj
Copy link
Member

laanwj commented Jun 11, 2012

@Diapolo ok, that's also a possibility, as it appears that nothing else can "fall through" to there

@laanwj
Copy link
Member

laanwj commented Jun 11, 2012

It does create another issue, though: the icon disappears before the shutdown starts, instead of after it ends. That's one of the things we were trying to prevent. It's useful to keep the icon until the program actually exits, to tell the user that something is running.

@Diapolo
Copy link
Author

Diapolo commented Jun 11, 2012

@laanwj Seems rather hard to ensure a clean shutdown and wanting to keep the tray-icon till the very end. Leaving the Qt Shutdown(NULL) were it was before leads to killing Qt objects. this looks much more sane now. So any further idea (perhaps in another pull if this requires additional re-work on the GUI)?

@Diapolo
Copy link
Author

Diapolo commented Jun 11, 2012

Perhaps move the Shutdown() back to where it was and re-add the #ifdef QT_GUI around the exit() in Shutdown(). This would make Bitcoin-Qt exit via the last return 0 in bitcoin.cpp.

@laanwj
Copy link
Member

laanwj commented Jun 11, 2012

Yeah - IMO, the idea to not call exit() at the end of the Shutdown() function in the case of the UI was good. This allows it to wind things down afterward instead of before.
(which will eventually also allow it to show some "Warning - do not shutdown computer while Bitcoin is shutting down" warning).

Edit: or even better: make it explicit and save an #ifdef. Create a ShutdownAndExit() function that shuts down and exits (calls Shutdown then exit), and a normal Shutdown() that just shuts down, then use each one at the appropriate place.

@Diapolo
Copy link
Author

Diapolo commented Jun 11, 2012

@laanwj I see 2 problems with your last suggestion.

  1. Shutdown() calls CreateThread(ExitTimeout, NULL); which seems to be a 5 second timer, before the process get's killed anyway, so the Shutdown() function still somehow exits / kills the client.
  2. I think an #ifdef is easier / cleaner than another function in this case.

@Diapolo
Copy link
Author

Diapolo commented Jun 11, 2012

Updated to ensure tray-icon is kept until Bitcoin-Qt exits, no further changes for no UI client.

@TheBlueMatt
Copy link
Contributor

Well, it ended up with more ifdefs than I thought it would need, but it still looks better than it was imho, ACK.

Copy link
Member

Choose a reason for hiding this comment

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

This comment is no longer needed :)

Copy link
Author

Choose a reason for hiding this comment

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

A final update, which only removes this line was pushed ^^.

@laanwj
Copy link
Member

laanwj commented Jun 12, 2012

ACK

…Shutdown() if no GUI is used and calls uiInterface.QueueShutdown() if a GUI is used / all direct uiInterface.QueueShutdown() calls are replaced with Shutdown() - this ensures a clean GUI shutdown, even when catching a SIGTERM and allows the BitcoinGUI destructor to get called (which fixes a tray-icon issue and keeps the tray-icon until Bitcoin-Qt exits)
@TheBlueMatt
Copy link
Contributor

Note for whoever merges, close #1182, as this fixes it.

@laanwj
Copy link
Member

laanwj commented Jun 13, 2012

I think we should aim to merge this asap, but as this affects critical functionality Gavin or Sipa should probably take a look at it for a sanity check.

@sipa
Copy link
Member

sipa commented Jun 13, 2012

ACK on the changes to core; The exit(0) in Shutdown inside ifndef qt is a bit ugly though, imho.

@laanwj
Copy link
Member

laanwj commented Jun 13, 2012

Well, IMO the problem is that "shutdown bitcoin" and "exit program" are essentially different actions.

That's why I proposed adding a ShutdownAndExit function, and using that where appropriate: in StartShutdown [ifndef QT_GUI] and AppInit. The name would also clearly signal to the programmer that the function never returns. The normal Shutdown function would shut down bitcoin and return.

Diapolo thought it'd be less clear, but I think it'd be better to be explicit.

laanwj added a commit that referenced this pull request Jun 14, 2012
@laanwj laanwj merged commit 0f10b21 into bitcoin:master Jun 14, 2012
coblee pushed a commit to litecoin-project/litecoin that referenced this pull request Jul 17, 2012
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Jan 22, 2019
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request May 6, 2020
0a85445 [Core] Add -debugexclude option (random-zebra)

Pull request description:

  Implemented on top of:
  - [x] bitcoin#1449
  - [x] bitcoin#1437

  Backports bitcoin#10123

  > setting `-debug` can lead to very noisy debug.logs with subcomponents filling up the log file. See for example https://travis-ci.org/bitcoin/bitcoin/jobs/216767286 where there are hundreds of libevent debug logs.

  This commit adds an option to exclude certain components from debug logging. The usage is:
  ```
  pivxd -debug -debugexclude=<component1> -debugexclude=<component2> ...
  ```

  This finally reduces spammy logs in the functional tests debug, due to libevent and leveldb (bitcoin#10124 was already included backporting the test suite).

ACKs for top commit:
  furszy:
    Code looking good, utACK 0a85445 .
  Fuzzbawls:
    ACK 0a85445

Tree-SHA512: 6ccbe275ab11f3e1739ed117e49db0a2e56db345287cddc7cc18fc1131d7800d0f08a7e93005f70cf45ed8e340580f91c3017532bd2ea28fedb5735409ae068b
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request May 6, 2020
d16b7b2 Buffer log messages and explicitly open logs (random-zebra)

Pull request description:

  implemented on top of
  - [x] bitcoin#1449
  - [x] bitcoin#1437
  - [x] bitcoin#1439

  Backports bitcoin#6149

  > Prevents stomping on debug logs in datadirs that are locked by other
  instances and lost parameter interaction messages that can get wiped by
  ShrinkDebugFile().
  The log is now opened explicitly and all emitted messages are buffered
  until this open occurs.  The version message and log cut have also been
  moved to the earliest possible sensible location.

ACKs for top commit:
  furszy:
    utACK d16b7b2
  Fuzzbawls:
    ACK d16b7b2

Tree-SHA512: f3f859181499661641df1ccf118fdb583517c3f4104313df4c200471436e2c456bd9d15164215cfde274b235afdd2afe19a186c214d3c06461f0e3a03bd944b8
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request May 6, 2020
f66e50e [Doc] Add logging RPC to release notes (random-zebra)
bf55911 allow libevent logging to be updated during runtime (random-zebra)
ec43b51 Set BCLog::LIBEVENT correctly for old libevent versions. (random-zebra)
cbaf724 [rpc] Add logging rpc (random-zebra)

Pull request description:

  Implemented on top of:
  - [x] bitcoin#1449
  - [x] bitcoin#1437
  - [x] bitcoin#1439
  - [x] bitcoin#1450

  Backports bitcoin#10150

  > Adds an RPC to get/set active logging categories.
  First commit allows all categories except libevent to be reconfigured during runtime.
  Second commit modifies InitHTTPServer() to allow leveldb logging to be reconfigured during runtime.

ACKs for top commit:
  furszy:
    Really nice 👍 , ACK f66e50e .
  Fuzzbawls:
    ACK f66e50e

Tree-SHA512: 7b735628d341fb8661eb76f57dadc78e69ea63c62edb778450b3d9e3b7137ce06e08ceab835967b923401a9687e5b2605722a9f256e6ed85fc372a0e46086b8f
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request May 6, 2020
882ef90 [Doc] Update release notes for `-debuglogfile` (random-zebra)
3d5ad7f test: Add tests for `-debuglogfile` with subdirs (random-zebra)
2c2e36d test: Add test for `-debuglogfile` (random-zebra)
b44a324 Add `-debuglogfile` option (random-zebra)

Pull request description:

  Implemented on top of
  - [x] bitcoin#1449
  - [x] bitcoin#1437
  - [x] bitcoin#1439
  - [x] bitcoin#1450
  - [x] bitcoin#1451

  Only last 4 commits are relevant to this PR.
  Backports bitcoin#11781

  > This patch adds an option to configure the name and/or directory of the debug log file.</br></br>
  The user can specify either a relative path, in which case the path is relative to the (network specific) data directory. They can also specify an absolute path to put the log anywhere else in the file system.

  Functional test included.

ACKs for top commit:
  Fuzzbawls:
    ACK 882ef90
  furszy:
    utACK 882ef90

Tree-SHA512: 02a0e6487683e5111765af7296ef7ce035372febf037268d99d29b4c4a2f74bcc40f46a0f5b1bacddc2249c2a7e40255555e83ca9d51bf71d9e054c6e85765cc
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request May 6, 2020
5c8e968 [Trivial] Document logtimemicros flag in the help (random-zebra)
4daa10a util: Store debug log file path in BCLog::Logger member. (random-zebra)
2f03e85 scripted-diff: Rename BCLog::Logger member variables. (random-zebra)
303700e util: Refactor GetLogCategory. (random-zebra)
0ae18c0 util: Encapsulate logCategories within BCLog::Logger. (random-zebra)
a2fb3fd util: Move debug file management functions into Logger. (random-zebra)
5a42d82 util: Establish global logger object. (random-zebra)
15c0da4 [Refactor] Complete boost::filesystem namespace in util (random-zebra)
81ddbf4 MOVEONLY: Move logging code from util.{h,cpp} to new files. (random-zebra)

Pull request description:

  Implemented on top of:
  - [x] bitcoin#1449
  - [x] bitcoin#1437
  - [x] bitcoin#1439
  - [x] bitcoin#1450
  - [x] bitcoin#1451
  - [x] bitcoin#1455

  This creates a new class BCLog::Logger to encapsulate all global logging configuration and state.

  Adapted from
  - bitcoin#13021
  - bitcoin#12954

ACKs for top commit:
  Fuzzbawls:
    ACK 5c8e968
  furszy:
    utACK 5c8e968

Tree-SHA512: 0b10a031dd7e32b48485236fbdd8249d011049e6f99e1df145b7dea4cab9e6e67e19d1bb13ff48e99eb2487a8399bbb8298fe851ad8873416fc1053aee0379bc
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bitcoin-qt usually SEGVs when exited using unix signals

4 participants