decred / dcrwallet

A secure Decred wallet daemon written in Go (golang).
https://decred.org
ISC License
219 stars 156 forks source link

panic on shutdown #482

Closed jcvernaleo closed 7 years ago

jcvernaleo commented 7 years ago

I was able to hit a panic when shutting down wallet with the rpc command:

13:17:23 2016-12-20 [INF] DCRW: Received shutdown request.  Shutting down...
13:17:23 2016-12-20 [WRN] DCRW: Stopping legacy RPC server...
13:17:23 2016-12-20 [INF] TKBY: Stopping ticket buyer
unexpected fault address 0x235789008
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x1 addr=0x235789008 pc=0x998d29]

goroutine 66 [running]:
runtime.throw(0xbb141c, 0x5)
        /home/jcv/code/golang/src/runtime/panic.go:566 +0x95 fp=0xc420116b78 sp=0xc420116b58
runtime.sigpanic()
        /home/jcv/code/golang/src/runtime/sigpanic_unix.go:27 +0x288 fp=0xc420116bd0 sp=0xc420116b78
github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt.(*Cursor).search(0xc422809740, 0x22dc0c030, 0x44, 0x44, 0x15697)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt/cursor.go:255 +0x69 fp=0xc420116c98 sp=0xc420116bd0
github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt.(*Cursor).searchPage(0xc422809740, 0x22dc0c030, 0x44, 0x44, 0x22cad8000)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt/cursor.go:314 +0x13c fp=0xc420116d28 sp=0xc420116c98
github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt.(*Cursor).search(0xc422809740, 0x22dc0c030, 0x44, 0x44, 0xc9e6)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt/cursor.go:271 +0x1b6 fp=0xc420116df0 sp=0xc420116d28
github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt.(*Cursor).searchPage(0xc422809740, 0x22dc0c030, 0x44, 0x44, 0x226d0e000)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt/cursor.go:314 +0x13c fp=0xc420116e80 sp=0xc420116df0
github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt.(*Cursor).search(0xc422809740, 0x22dc0c030, 0x44, 0x44, 0x6c1c)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt/cursor.go:271 +0x1b6 fp=0xc420116f48 sp=0xc420116e80
github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt.(*Cursor).seek(0xc422809740, 0x22dc0c030, 0x44, 0x44, 0x0, 0xc42045c000, 0xc421e5f601, 0x267ba4000, 0x0, 0xb11920, ...)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt/cursor.go:159 +0xb1 fp=0xc420116f98 sp=0xc420116f48
github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt.(*Cursor).Seek(0xc422809740, 0x22dc0c030, 0x44, 0x44, 0xc422809701, 0xc4200138c0, 0xc420117060, 0x41feef, 0xb59160, 0xc4200138c0)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/boltdb/bolt/cursor.go:118 +0x50 fp=0xc420117000 sp=0xc420116f98
github.com/decred/dcrwallet/walletdb/bdb.(*cursor).Seek(0xc422809740, 0x22dc0c030, 0x44, 0x44, 0xc4200138c0, 0x1077580, 0xc4200138c0, 0xc420019b40, 0x2ad314f40, 0xc422809740)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/walletdb/bdb/db.go:270 +0x4d fp=0xc420117060 sp=0xc420117000
github.com/decred/dcrwallet/wtxmgr.(*readCursor).Seek(0xc4200138c0, 0x22dc0c030, 0x44, 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        <autogenerated>:12 +0x6b fp=0xc4201170c0 sp=0xc420117060
github.com/decred/dcrwallet/wtxmgr.(*creditIterator).next(0xc4201173c0, 0xc421e5f640)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/wtxmgr/db.go:1164 +0x211 fp=0xc420117140 sp=0xc4201170c0
github.com/decred/dcrwallet/wtxmgr.(*Store).minedTxDetails(0xc430afc0c0, 0x206be7c20, 0xc421e5f640, 0xc425a72660, 0x22dc0c030, 0x44, 0x44, 0x22dc0c074, 0x5f5, 0x5f5, ...)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/wtxmgr/query.go:73 +0x217 fp=0xc420117450 sp=0xc420117140
github.com/decred/dcrwallet/wtxmgr.(*Store).TxDetails(0xc430afc0c0, 0x206be7c20, 0xc421e5f640, 0xc425a72660, 0x0, 0x0, 0x0)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/wtxmgr/query.go:193 +0x18e fp=0xc4201174c8 sp=0xc420117450
github.com/decred/dcrwallet/wallet.(*Wallet).StakeInfo.func1(0x1070ce0, 0xc42002a418, 0xc42002a418, 0x0)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/wallet/wallet.go:2971 +0xbf4 fp=0xc4201177f0 sp=0xc4201174c8
github.com/decred/dcrwallet/walletdb.View(0x10751a0, 0xc4204c43c0, 0xc420117878, 0x0, 0x636daa)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/walletdb/interface.go:197 +0x6f fp=0xc420117848 sp=0xc4201177f0
github.com/decred/dcrwallet/wallet.(*Wallet).StakeInfo(0xc42000c6c0, 0x63692e, 0xc420445100, 0x1)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/wallet/wallet.go:3044 +0x9a fp=0xc4201178a8 sp=0xc420117848
github.com/decred/dcrwallet/ticketbuyer.(*TicketPurchaser).ownTicketsInMempool(0xc4200e83c0, 0x404a538155551c11, 0x77, 0xc421e5f580)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/mempool.go:73 +0x6e fp=0xc420117970 sp=0xc4201178a8
github.com/decred/dcrwallet/ticketbuyer.(*TicketPurchaser).Purchase(0xc4200e83c0, 0x3883b, 0x19, 0xc4250a2000, 0x1)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/buyer.go:481 +0xac7 fp=0xc420117e58 sp=0xc420117970
github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).purchase(0xc420622020, 0x3883b)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:35 +0xf8 fp=0xc420117ee0 sp=0xc420117e58
github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler.func1(0xc420444a00, 0xc420622020, 0xc4206442a0, 0xc420644300)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:54 +0xd3 fp=0xc420117f80 sp=0xc420117ee0
runtime.goexit()
        /home/jcv/code/golang/src/runtime/asm_amd64.s:2086 +0x1 fp=0xc420117f88 sp=0xc420117f80
created by github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:57 +0x162

goroutine 1 [runnable]:
github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.(*asyncLogger).Flush(0xc420445100)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/behavior_asynclogger.go:87
main.walletMain(0x0, 0x0)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/dcrwallet.go:205 +0x881
main.main()
        /home/jcv/code/go/src/github.com/decred/dcrwallet/dcrwallet.go:39 +0x32

goroutine 5 [semacquire, 30 minutes]:
sync.runtime_notifyListWait(0xc420019a50, 0x0)
        /home/jcv/code/golang/src/runtime/sema.go:267 +0x122
sync.(*Cond).Wait(0xc420019a40)
        /home/jcv/code/golang/src/sync/cond.go:57 +0x80
github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.(*asyncLoopLogger).processItem(0xc420016960, 0x0)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/behavior_asynclooplogger.go:50 +0x97
github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.(*asyncLoopLogger).processQueue(0xc420016960)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/behavior_asynclooplogger.go:63 +0x33
created by github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.newAsyncLoopLogger
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/behavior_asynclooplogger.go:40 +0x96

goroutine 6 [semacquire, 30 minutes]:
sync.runtime_notifyListWait(0xc420019c50, 0x0)
        /home/jcv/code/golang/src/runtime/sema.go:267 +0x122
sync.(*Cond).Wait(0xc420019c40)
        /home/jcv/code/golang/src/sync/cond.go:57 +0x80
github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.(*asyncLoopLogger).processItem(0xc420016a80, 0x0)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/behavior_asynclooplogger.go:50 +0x97
github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.(*asyncLoopLogger).processQueue(0xc420016a80)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/behavior_asynclooplogger.go:63 +0x33
created by github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.newAsyncLoopLogger
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/behavior_asynclooplogger.go:40 +0x96

goroutine 37 [syscall, 30 minutes]:
os/signal.signal_recv(0xc420029fa8)
        /home/jcv/code/golang/src/runtime/sigqueue.go:116 +0x157
os/signal.loop()
        /home/jcv/code/golang/src/os/signal/signal_unix.go:22 +0x22
created by os/signal.init.1
        /home/jcv/code/golang/src/os/signal/signal_unix.go:28 +0x41

goroutine 38 [runnable]:
fmt.(*pp).doPrint(0xc4243180c0, 0xc421d8f4e0, 0x2, 0x2)
        /home/jcv/code/golang/src/fmt/print.go:1105
fmt.Sprint(0xc421d8f4e0, 0x2, 0x2, 0xc42558d680, 0x0)
        /home/jcv/code/golang/src/fmt/print.go:232 +0x56
github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.(*logMessage).String(0xc421d8f500, 0xd6db02, 0x1077be0)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/logger.go:365 +0x40
github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.(*commonLogger).processLogMsg(0xc420445100, 0xb30002, 0x106c620, 0xc421d8f500, 0x1077be0, 0xc4200174a0)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/logger.go:312 +0x9c
github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.(*asyncLogger).processQueueElement(0xc420445100)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/behavior_asynclogger.go:112 +0x118
github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.(*asyncAdaptiveLogger).processItem(0xc420445100, 0xc423ee4900, 0x0)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/behavior_adaptivelogger.go:101 +0xcd
github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.(*asyncAdaptiveLogger).processQueue(0xc420445100)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/behavior_adaptivelogger.go:119 +0x37
created by github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog.newAsyncAdaptiveLogger
        /home/jcv/code/go/src/github.com/decred/dcrwallet/vendor/github.com/btcsuite/seelog/behavior_adaptivelogger.go:84 +0x1b5

goroutine 12 [select, 29 minutes, locked to thread]:
runtime.gopark(0xd6f140, 0x0, 0xbb29e5, 0x6, 0x18, 0x2)
        /home/jcv/code/golang/src/runtime/proc.go:259 +0x13a
runtime.selectgoImpl(0xc420105730, 0x0, 0x18)
        /home/jcv/code/golang/src/runtime/select.go:423 +0x11d9
runtime.selectgo(0xc420105730)
        /home/jcv/code/golang/src/runtime/select.go:238 +0x1c
runtime.ensureSigM.func1()
        /home/jcv/code/golang/src/runtime/signal1_unix.go:304 +0x2d6
runtime.goexit()
        /home/jcv/code/golang/src/runtime/asm_amd64.s:2086 +0x1

goroutine 24 [chan receive, 24 minutes]:
github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler.func1(0xc42154e000, 0xc420622020, 0xc420644300, 0xc423c06000)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:52 +0x55
created by github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:57 +0x162

goroutine 98 [chan receive, 3 minutes]:
github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler.func1(0xc431156200, 0xc420622020, 0xc421d14000, 0xc423ed4000)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:52 +0x55
created by github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:57 +0x162

goroutine 26 [chan receive, 13 minutes]:
github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler.func1(0xc431156180, 0xc420622020, 0xc42149a000, 0xc423fde000)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:52 +0x55
created by github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:57 +0x162

goroutine 83 [chan receive, 16 minutes]:
github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler.func1(0xc431294100, 0xc420622020, 0xc423c06000, 0xc42149a000)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:52 +0x55
created by github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:57 +0x162

goroutine 85 [chan receive, 10 minutes]:
github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler.func1(0xc431156100, 0xc420622020, 0xc423fde000, 0xc423c06060)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:52 +0x55
created by github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:57 +0x162

goroutine 86 [chan receive, 6 minutes]:
github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler.func1(0xc42154e180, 0xc420622020, 0xc423c06060, 0xc421d14000)
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:52 +0x55
created by github.com/decred/dcrwallet/ticketbuyer.(*PurchaseManager).NotificationHandler
        /home/jcv/code/go/src/github.com/decred/dcrwallet/ticketbuyer/purchase.go:57 +0x162
jcv@yoshi ~ $

This was with wallet master as of roughly 12/20/2016

jrick commented 7 years ago

@tuxcanfly want to make sure you see this.

We need a way to wait until the ticket buyer completely shuts down (not just after we tell it to stop) before we can close the database. Otherwise we end up with this segfault because it is accessing mmapped memory that is no longer mapped to the process.

481 would be a nice fix for this but I don't think we want to work on trying to jam that into the release at the last minute. But even doing that will require blocking on complete shutdown of the ticket buyer.