There are four things that need to be addressed for restart to work properly on mobile builds. Links tp the PR's will be here once they are up.
btcwallet.Loader.UnloadWallet on shutdown](https://github.com/lightningnetwork/lnd/pull/4591)This is on Android, I cannot test if the same thing happens on iOS builds.
Attempting to "restart" lnd by running stopDaemon and then starting lnd again with the normal start entry from the mobile package results in a crash.
E/Go: panic: close of closed channel
goroutine 270 [running]:
github.com/lightningnetwork/lnd/signal.mainInterruptHandler()
/home/coco/go/src/github.com/lightningnetwork/lnd/signal/signal.go:82 +0x26e
created by github.com/lightningnetwork/lnd/signal.Intercept
/home/coco/go/src/github.com/lightningnetwork/lnd/signal/signal.go:39 +0xe1
A/libc: Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 20434 (Thread-5), pid 20335 (example.lndtest)
Lnd logs this:
2020-07-28 17:27:54.027 [INF] LTND: REST API is disabled!
2020-07-28 17:27:54.028 [INF] LTND: Listening on the p2p interface is disabled!
2020-07-28 17:27:54.028 [INF] LTND: Version: 0.10.99-beta commit=clock/v1.0.0-246-g22cd1203fe96a1417b428a009f4e28d31f921d85, build=development, logging=default
2020-07-28 17:27:54.028 [INF] LTND: Active chain: Bitcoin (network=testnet)
2020-07-28 17:27:54.028 [INF] LTND: Opening the main database, this might take a few minutes...
2020-07-28 17:27:54.031 [INF] CHDB: Checking for schema update: latest_version=17, db_version=17
2020-07-28 17:27:54.032 [INF] LTND: Database now open (time_to_open=3.3948ms)!
This is on master at the time of writing (22cd1203fe96a1417b428a009f4e28d31f921d85), but the bug has existed since the beginning of mobile builds.
lnd master (22cd1203fe96a1417b428a009f4e28d31f921d85), but any version would sufficeI have a repository up here where you can see the issue in action: https://github.com/hsjoberg/lndmobile-speed-tests
Monitor via logcat.
To test: Click on writeConfig, then startLnd, then InitWallet.
After lnd has opened the wallet, click on stopDaemon. Tying to run startLnd again will result in a crash.
My guess is that some subserver or something isn't properly stopped.
I would be happy to help on this issue, this is really important for me. Although I don't know what's wrong.
Running start after stopDaemon should start the lnd again.
Lnd crashes (which makes the main android app crash as well).
Thanks for raising it, it is something we have been aware of from the beginning. Definitely something that would be nice to fix, I think a prerequisite would be #3982
Confirming similar behavior on iOS. Attached image shows GRPC debug log. As noted in issue #4500 , this too results in "leaking" promise.

Confirming behavior on iOS with a different log
2020-08-05 18:35:42.945 [INF] LTND: Version: 0.10.99-beta commit=clock/v1.0.0-217-g77549f1fb8f046fc565d42151a4ae3900391170e-dirty, build=development, logging=default
2020-08-05 18:35:42.945 [INF] LTND: Active chain: Bitcoin (network=testnet)
2020-08-05 18:35:42.945 [INF] LTND: Opening the main database, this might take a few minutes...
2020-08-05 18:35:42.947 [INF] LTND: Gracefully shutting down.
panic: close of closed channel
goroutine 38660 [running]:
github.com/lightningnetwork/lnd/signal.mainInterruptHandler()
go/src/github.com/lightningnetwork/lnd/signal/signal.go:82 +0x224
created by github.com/lightningnetwork/lnd/signal.Intercept
go/src/github.com/lightningnetwork/lnd/signal/signal.go:39 +0xcc
I've now opened pull requests covering everything that is needed to fix restarting lnd.
Most helpful comment
Thanks for raising it, it is something we have been aware of from the beginning. Definitely something that would be nice to fix, I think a prerequisite would be #3982