Repository: bitcoin
Issue: ThreadDNSAddressSeed hangs on sk_wait_data and doesn't stop on exit
Labels: P2P

This is a continue of previously opened issue [Unable to stop bitcoin-qt. ThreadDNSAddressSeed hangs. #16642](https://github.com/bitcoin/bitcoin/issues/16642#issue-481935673). Now hardware problems are sorted out. Single consumer-grade HDD on USB3.0 is changed for RAID1 of HGST Ultrastar® 7K4000 on SATA. Database was changed for know working archived version. Except already repaired HDD problem, hardware is stable, none failures or glitches was found for several month of operation under different operating systems.

The problem is sometimes Bitcoin Core, particularly bitcoin-qt, unable to finish it's operation on close.
I'm expecting normal bitcoin-qt application finishing after clicking "close" sign at top right corner of main GUI window.
Actual behavior: after several successful application shutdowns, the application remains to hang with a message "Bitcoin Core is shutting down... Don't shut down the computer until this window dissapears."
Natively compiled 01 Sep 2019 for arm-linux-gnueabihf, master branch.

Debug output:
```
2019-09-01T07:44:54Z GUI: requestShutdown : Requesting shutdown
2019-09-01T07:44:54Z GUI: shutdown : Running Shutdown in thread
2019-09-01T07:44:54Z Interrupting HTTP server
2019-09-01T07:44:54Z Interrupting HTTP RPC server
2019-09-01T07:44:54Z Interrupting RPC
2019-09-01T07:44:54Z addcon thread exit
2019-09-01T07:44:54Z opencon thread exit
2019-09-01T07:44:54Z msghand thread exit
2019-09-01T07:44:54Z Shutdown: In progress...
2019-09-01T07:44:54Z Stopping HTTP RPC server
2019-09-01T07:44:54Z Stopping RPC
2019-09-01T07:44:54Z Stopping HTTP server
2019-09-01T07:44:54Z Stopped HTTP server
2019-09-01T07:44:54Z net thread exit
2019-09-01T07:44:54Z BerkeleyEnvironment::Flush: [/bdb] Flush(false)
2019-09-01T07:44:54Z BerkeleyEnvironment::Flush: Flushing wallet.dat (refcount = 0)...
2019-09-01T07:44:55Z BerkeleyEnvironment::Flush: wallet.dat checkpoint
2019-09-01T07:44:55Z BerkeleyEnvironment::Flush: wallet.dat detach
2019-09-01T07:44:55Z BerkeleyEnvironment::Flush: wallet.dat closed
2019-09-01T07:44:55Z BerkeleyEnvironment::Flush: Flush(false) took             271ms
2019-09-01T07:58:54Z Flushed 64452 addresses to peers.dat  1854ms
2019-09-01T08:13:56Z Flushed 64452 addresses to peers.dat  2216ms
2019-09-01T08:22:11Z Potential stale tip detected, will try using extra outbound peer (last tip update: 2245 seconds ago)
2019-09-01T08:22:11Z net: setting try another outbound peer=true
2019-09-01T08:28:58Z Flushed 64452 addresses to peers.dat  1895ms

```

Threads after shutdown request:
```
rock@Debian-Desktop:~$ ps -eLl
...
F S   UID   PID  PPID   LWP  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000  3094  1336  3094  4  80   0 - 139807 poll_s pts/0   00:02:43 bitcoin-main
1 S  1000  3094  1336  3095  0  80   0 - 139807 poll_s pts/0   00:00:01 QXcbEventReader
1 S  1000  3094  1336  3097  0  80   0 - 139807 futex_ pts/0   00:00:00 mali-mem-purge
1 S  1000  3094  1336  3098  0  80   0 - 139807 futex_ pts/0   00:00:00 mali-utility-wo
1 S  1000  3094  1336  3099  0  80   0 - 139807 futex_ pts/0   00:00:00 mali-utility-wo
1 S  1000  3094  1336  3100  0  80   0 - 139807 futex_ pts/0   00:00:00 mali-utility-wo
1 S  1000  3094  1336  3101  0  80   0 - 139807 futex_ pts/0   00:00:00 mali-utility-wo
1 S  1000  3094  1336  3102  0  80   0 - 139807 futex_ pts/0   00:00:00 mali-utility-wo
1 S  1000  3094  1336  3103  0  80   0 - 139807 futex_ pts/0   00:00:00 mali-utility-wo
1 S  1000  3094  1336  3104  0  80   0 - 139807 poll_s pts/0   00:00:00 mali-cmar-backe
1 S  1000  3094  1336  3105  0  80   0 - 139807 futex_ pts/0   00:00:00 mali-hist-dump
1 S  1000  3094  1336  3106  0  80   0 - 139807 poll_s pts/0   00:00:00 QDBusConnection
1 S  1000  3094  1336  3112  3  80   0 - 139807 futex_ pts/0   00:01:54 bitcoin-shutoff
1 S  1000  3094  1336  3117  0  80   0 - 139807 futex_ pts/0   00:00:26 bitcoin-scriptc
1 S  1000  3094  1336  3118  0  80   0 - 139807 futex_ pts/0   00:00:17 bitcoin-schedul
1 S  1000  3094  1336  3122 17  80   0 - 139807 futex_ pts/0   00:09:23 bitcoin-qt-init
1 S  1000  3094  1336  3151  0  80   0 - 139807 sk_wai pts/0   00:00:00 bitcoin-dnsseed
1 S  1000  3094  1336  3156  0  80   0 - 139807 poll_s pts/0   00:00:00 QThread
1 S  1000  3094  1336  3157  0  80   0 - 139807 poll_s pts/0   00:00:00 Qt bearer threa
...
```
The issue is reproducing quite reliable. With 0.18 versions on different computers, different builds I had this problem at least three times even after DB rescan. For some time the Core works normally but at some point, usually after network disturbance, it hangs on shutdown.

Now it is self-compiled from https://github.com/bitcoin/bitcoin.git
Bitcoin Core version v0.18.99.0-495db72ee-dirty
The machine is ROCKPro64, RK3399 CPU, 4GB RAM.
Configure command was:
```
./configure --enable-debug --enable-werror BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include" --with-boost-libdir=/usr/lib/arm-linux-gnueabihf
```
This time I compiled the Core with debug enabled. If being provided with more debug instructions I will try to investigate it deeper.
After the compilation and installation, test_bitcoin was completed with none errors.

As I wrote in #16642 before, the problem persist not only at mine ARM CPU but on an Intel CPU too.

Thank you.