mirror of
https://github.com/bitcoin-core/gui-qml.git
synced 2026-12-02 07:42:38 +00:00
macOS: wallet notifications arriving close together can crash the app once the Addresses or View coins page has been opened #1119
Labels
No labels
Android
Bug
Build system
Design suggestion
Doc
Needs design review
Needs rebase
Stage
UX
Up for grabs
Upstream
Wallet
duplicate
enhancement
good first issue
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin-core/gui-qml#1119
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
On macOS, two wallet notifications arriving close together can kill the app once its Addresses page or its View coins page (both under Wallet settings) has been opened and that page's list has rows out of view. On Addresses, address-label changes over RPC do it, and so do incoming payments, a block confirming several of the wallet's payments, and new addresses. On View coins, incoming payments and such a block do it; label changes and new addresses were not tried there. Saving a label in the app by hand does not trigger it.
To reproduce:
setlabelcalls on that wallet at the same time.The process exits within about 0.2 s, with nothing about the crash on stderr and an ordinary
debug.log. It ends with SIGBUS, or with SIGTRAP when libmalloc reports a corrupted free block.setlabelcalls, default windowsetlabelcalls, 1180x1100 windowsetlabelcallssetlabelcallThe crashing thread is the main thread:
This stack is from the Addresses list. No stack was taken with View coins.
Each label change makes the wallet's address-book notification queue a
refresh()of the address model (walletqmlmodel.cpp#L3217-L3221, addresslistmodel.cpp#L64), and every wallet transaction or lock-state notification does the same throughbalanceChanged(walletqmlmodel.cpp#L3209-L3240, addresslistmodel.cpp#L65). Each refresh resets the whole model. The coins model behind View coins listens to the same notifications and resets itself twice on each (coinslistmodel.cpp#L16-L18, coinslistmodel.cpp#L82-L121). By the stack, a reset that follows closely on another deletes a row delegate that is still being created, and while it is being deleted Qt's macOS accessibility code calls into the half-destroyed item. The faulting code is in Qt 6.9.0; the app supplies the back-to-back resets. #1084 covers what these resets do to an edit in progress and to the list position.Suggested: coalesce the refreshes, or update rows in place, in both models, so that wallet notifications do not reset a whole list each time.
Open question
I could not settle whether an accessibility client must be running. Qt's Cocoa accessibility layer acts only once something has queried the window's accessibility interface, so in the runs that produced a stack, something had. A window manager that uses that interface was running during the runs in the table. With it closed, six concurrent calls still crashed 2 of 3, with no stack captured. I did not test with VoiceOver.
These also avoided the crash:
QSG_RENDER_LOOP=basic(0 of 2), and one run under Guard Malloc.Reproduced on merged
qt6ateed1f426fcb6, macOS arm64 with Homebrew Qt 6.9.0, isolated regtest. macOS wrote no crash report and a debugger could not attach, so the stacks come from a signal handler preloaded into some of the test launches. Three were captured, two from RPC runs and one from a programmatic save, and they show the crashing thread only. It needs two wallet notifications arriving within a few tens of milliseconds of each other. Label changes from outside the app are one way; incoming payments and blocks are another, and a block or two relayed payments received from a peer are enough.This does not need label changes or an outside program. Any two wallet notifications about 10 ms apart do it, the page only has to have been opened, and View coins is affected as well as Addresses.
At
2bd5a61e8304, native window at the default size, 16 unused addresses, Wallet settings → Addresses showing unless noted. Crashed means the process was gone within 0.3 s of the event with SIGBUS or SIGTRAP:getnewaddresscallseed1f426fcb6gave the same: 9 of 10 with 20 payments, 6 of 10 with two.The same with Wallet settings → View coins in place of Addresses, in launches where Addresses was never opened. Wallet with 20 coins unless noted; about three rows fit at the default window size:
eed1f426fcb6: 6 of 10 with 20 payments, 0 of 10 with one.With a second regtest node on localhost as the app's only peer, holding the paying wallet, so that nothing was sent to the app's own RPC:
The two relayed payments reached the wallet 5 to 11 ms apart and the two confirmations 4 to 14 ms apart. In the same rounds as the peer table the two-payment case on Addresses, over RPC, crashed 10 of 11. Between two
bitcoindnodes with no GUI, two payments submitted to the relaying node up to 2 s apart reached the receiving wallet 5 to 18 ms apart in 11 of 12 tries; submitted 4 s apart they arrived seconds apart in 3 of 3.The address model refreshes on
balanceChangedas well as on the address-book signal, and every wallet transaction emits it, so each payment or confirmation resets the whole list. The coins model is connected totransactionChanged,addressListChangedandbalanceChangedand resets twice per call (coinslistmodel.cpp#L16-L18, coinslistmodel.cpp#L82-L121), so each payment or confirmation resets that list four times. Leaving either page by a tab keeps it on the settings stack (WalletSettingsStack.qml#L72-L108), so the list is still there to be reset; Back removes it.So a wallet with a screenful of unused addresses, or with six or more coins, with Addresses or View coins opened and left by a tab rather than with Back, can die when a block confirms two of its pending payments, or when two payments arrive together.
On the open question: Qt turns its Cocoa accessibility layer on only when another process queries the window, and the faulting frames are behind that check. With the same window manager running throughout, Qt's own log showed the layer active in 13 of 28 launches, and the crash rate followed it: two payments crashed 7 of 10 and 7 of 14 in periods where it was active, 0 of 3 where it mostly was not. I have still not tested with every accessibility client closed, nor with VoiceOver.
#990 at
389e2f1dac5cdoes not fix this. Run against its base with launches alternating, it crashed 36 of 40 on Addresses against 8 of 28, and 8 of 20 on View coins against 3 of 20; the base ran below its usual rate, so I can't say it is worse, only that it is not better. A burst becomes one reset per worker round and the coins model listens to the same coalesced signal, but the resets are still full, the coins model still resets twice per refresh, and two a round apart remain. The numbers are in my comment there.Limits:
On
qt6atefc4a2c754eb, after #1052, the Addresses crash no longer happens in my runs. #1052 does not fix it, though: one change inSkeleton.qmlmakes it much harder to reach.I bisected #1052 natively, running
2bd5a61e8304in the same minutes as a control at every step (Addresses showing, 20 payments back to back, window active).ad3a496a86crashed in 5 of 5 launches. The next commit,2cca32e868, crashed in 0 of 5, while the control crashed in 5 of 5. That commit changedSkeleton.qmlfromrunning: loadingtorunning: root.loading && root.visible && …. Before it, the three loading skeletons in the hidden column of the Activity page animated for the whole session. Removing onlyroot.visibleonefc4a2c754ebbrings the crash back (4 of 6, published stack; unchanged build 0 of 6). Adding only&& root.visibleon2bd5a61e8304stops it (0 of 6; unchanged build 4 of 6).While any animation runs, Qt builds the asynchronous rows below the visible area right after each frame, so the next model reset finds a row half built and cancels it. When nothing animates, the row has not been started when the next reset comes. With a row half built, Qt 6.9.0 fails in two ways:
Accessible.name, no role) sends an accessibility hide event beforecomponentComplete()set its role, andQAccessibleQuickItem::rolecalls theQQuickControlvirtualaccessibleRole()on an object that is by then only aQQuickItem. Explicit roles on that button andAddressLabelremoved this crash.ContextMenuattached object of the BasicTextFieldwrites through a stale back-pointer into the object creator's freed memory (qqmlobjectcreator.cpp:863-874). This one is inferred from the code and from the fact that using the TemplatesTextFieldremoved it. Qt 6.10 removed these back-pointers (qt/qtdeclarative@72b4dff6c0).On
efc4a2c754ebthe full resets, the role-less details button and the BasicTextFieldare unchanged, so any animation running during a burst of notifications can bring the crash back. View coins with one hidden animation running crashed in 1 of 5 launches. I would keep this open until the resets are coalesced or rows are updated in place.macOS arm64 / Qt 6.9.0, isolated regtest, native window. Steps went through the test bridge and payments came over RPC. The bisect and the on/off experiments used local builds; I am not proposing any of those changes.