Skip to content

Shutdown #3234

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

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
- Reduced support for BitBox01
- Fix a bug that would prevent the app to perform firmware upgrade when offline.

# 4.47.1
- Linux: fix support for Wayland
- Linux: release device upon app close, enabling other apps to connect to the BitBox after the BitBoxApp closes

# 4.47.0
- Bundle BitBox02 firmware version v9.22.0
- Fix long transaction notes to show fully on multiple lines when necessary
Expand Down
9 changes: 7 additions & 2 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,12 +898,17 @@ func (backend *Backend) Environment() Environment {

// Close shuts down the backend. After this, no other method should be called.
func (backend *Backend) Close() error {
backend.ratesUpdater.Stop()
// Call this without `accountsAndKeystoreLock` as it eventually calls `DeregisterKeystore()`,
// which acquires the same lock.
if backend.usbManager != nil {
backend.usbManager.Close()
}

defer backend.accountsAndKeystoreLock.Lock()()

errors := []string{}

backend.ratesUpdater.Stop()

backend.uninitAccounts(true)

for _, coin := range backend.coins {
Expand Down
3 changes: 2 additions & 1 deletion backend/bridgecommon/bridgecommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ func Shutdown() {

log := logging.Get().WithGroup("server")
if globalShutdown != nil {
log.Info("Shutdown about to be called")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: is this still needed, or is it a debug leftover?

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 thought it's a helpful line anyway in case Shutdown gets stuck for whatever reason

globalShutdown()
log.Info("Shutdown called")
log.Info("Shutdown finished")
} else {
log.Info("Shutdown called, but backend not running")
}
Expand Down
22 changes: 22 additions & 0 deletions backend/devices/usb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type Manager struct {
onUnregister func(string)

updateCh chan struct{}
quitCh chan struct{}

socksProxy socksproxy.SocksProxy

Expand Down Expand Up @@ -118,6 +119,7 @@ func NewManager(
onRegister: onRegister,
onUnregister: onUnregister,
updateCh: make(chan struct{}),
quitCh: make(chan struct{}),
socksProxy: socksProxy,

log: logging.Get().WithGroup("manager"),
Expand Down Expand Up @@ -272,6 +274,14 @@ func (manager *Manager) Update() {
func (manager *Manager) listen() {
for {
select {
case <-manager.quitCh:
return
default:
}

select {
case <-manager.quitCh:
return
case <-manager.updateCh:
case <-time.After(time.Second):
}
Expand Down Expand Up @@ -336,3 +346,15 @@ func (manager *Manager) Start() {
go manager.listen()
manager.Update()
}

// Close closes and unregisters all devices.
func (manager *Manager) Close() {
manager.log.Info("Closing devices manager")
close(manager.quitCh)
for deviceID, device := range manager.devices {
manager.log.WithField("device-id", deviceID).Info("manager: closing device")
device.Close()
delete(manager.devices, deviceID)
manager.onUnregister(deviceID)
}
}
2 changes: 1 addition & 1 deletion backend/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const updateFileURL = "https://bitboxapp.shiftcrypto.io/desktop.json"

var (
// Version of the backend as displayed to the user.
Version = semver.NewSemVer(4, 47, 0)
Version = semver.NewSemVer(4, 47, 1)
)

// UpdateFile is retrieved from the server.
Expand Down
10 changes: 5 additions & 5 deletions frontends/qt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ linux:
mv build/BitBox build/linux-tmp
cp build/assets.rcc build/linux-tmp/
cp server/libserver.so build/linux-tmp
# Add Wayland libs so the app can run natively on Wayland too.
# The linuxdeployqt maintainer unfortunately refuses to support it automatically: https://github.com/probonopd/linuxdeployqt/issues/189
# The list of related plugins was found by: `find $(qmake -query QT_INSTALL_PLUGINS) | grep wayland`
cd build/linux-tmp && /opt/linuxdeployqt-continuous-x86_64.AppImage BitBox \
-bundle-non-qt-libs \
-unsupported-allow-new-glibc \
# Add Wayland libs so the app can run natively on Wayland too.
# The linuxdeployqt maintainer unfortunately refuses to support it automatically: https://github.com/probonopd/linuxdeployqt/issues/189
# The list of related plugins was found by: `find $(qmake -query QT_INSTALL_PLUGINS) | grep wayland`
-extra-plugins=platforms/libqwayland-generic.so,platforms/libqwayland-egl.so,wayland-graphics-integration-client,wayland-decoration-client,wayland-shell-integration
cp /usr/lib/x86_64-linux-gnu/nss/* build/linux-tmp/lib
# See https://github.com/probonopd/linuxdeployqt/issues/554#issuecomment-1761834180
Expand All @@ -45,8 +45,8 @@ linux:
cp resources/linux/usr/share/icons/hicolor/128x128/apps/bitbox.png build/linux-tmp
mkdir build/tmp-deb/opt/
cp -aR build/linux-tmp build/tmp-deb/opt/bitbox
cd build/linux && fpm --after-install ../../resources/deb-afterinstall.sh -s dir -t deb -n bitbox -v 4.47.0 -C ../tmp-deb/
cd build/linux && fpm --after-install ../../resources/deb-afterinstall.sh -s dir -t rpm -n bitbox -v 4.47.0 -C ../tmp-deb/
cd build/linux && fpm --after-install ../../resources/deb-afterinstall.sh -s dir -t deb -n bitbox -v 4.47.1 -C ../tmp-deb/
cd build/linux && fpm --after-install ../../resources/deb-afterinstall.sh -s dir -t rpm -n bitbox -v 4.47.1 -C ../tmp-deb/
# create AppImage
cd build/linux-tmp && /opt/linuxdeployqt-continuous-x86_64.AppImage BitBox -appimage -unsupported-allow-new-glibc
mv build/linux-tmp/BitBoxApp-*-x86_64.AppImage build/linux/
Expand Down
2 changes: 1 addition & 1 deletion frontends/qt/libserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern void handleURI(cchar_t* uri);
extern void serve(cppHeapFree cppHeapFreeFn, pushNotificationsCallback pushNotificationsFn, responseCallback responseFn, notifyUserCallback notifyUserFn, cchar_t* preferredLocale, getSaveFilenameCallback getSaveFilenameFn);
extern void systemOpen(cchar_t* url);
extern void goLog(cchar_t* msg);

extern void backendShutdown();
#ifdef __cplusplus
}
#endif
1 change: 1 addition & 0 deletions frontends/qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ int main(int argc, char *argv[])
delete view;
view = nullptr;
webClassMutex.unlock();
backendShutdown();
});

#if defined(_WIN32)
Expand Down
5 changes: 5 additions & 0 deletions frontends/qt/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ func goLog(msg *C.cchar_t) {
logging.Get().WithGroup("qt-frontend").Info(goMsg)
}

//export backendShutdown
func backendShutdown() {
bridgecommon.Shutdown()
}

func authResult(ok bool) {
bridgecommon.AuthResult(ok)
}
Expand Down
Loading