lightninglabs / neutrino

Privacy-Preserving Bitcoin Light Client
MIT License
894 stars 182 forks source link

blockmanager.Stop() never exists. #264

Closed dmigwi closed 1 year ago

dmigwi commented 1 year ago

I was debugging this crash:

panic: couldn't write cfheaders msg: unable to fetch chain tip: database not open

goroutine 197 [running]:
github.com/lightninglabs/neutrino.(*blockManager).getCheckpointedCFHeaders(0xc0020a3680, {0xc00a2cc000, 0x2b2, 0x350}, 0x0?, 0x0)
    /home/dmigwi/work/golang/pkg/mod/github.com/lightninglabs/neutrino@v0.14.2/blockmanager.go:1155 +0x11ae
github.com/lightninglabs/neutrino.(*blockManager).cfHandler(0xc0020a3680)
    /home/dmigwi/work/golang/pkg/mod/github.com/lightninglabs/neutrino@v0.14.2/blockmanager.go:623 +0x50b
github.com/lightninglabs/neutrino.(*blockManager).Start.func1()
    /home/dmigwi/work/golang/pkg/mod/github.com/lightninglabs/neutrino@v0.14.2/blockmanager.go:313 +0x174
created by github.com/lightninglabs/neutrino.(*blockManager).Start
    /home/dmigwi/work/golang/pkg/mod/github.com/lightninglabs/neutrino@v0.14.2/blockmanager.go:299 +0x10a
exit status 2

Before closing the db, I shutdown the chain service. What amazes me is that despite me closing the chain service, some how it keeps running in the background resulting to the above crash.

While investigating the blockmanager code below: https://github.com/lightninglabs/neutrino/blob/88d8515ef499771f13f37fc94c7f438d7bce3758/blockmanager.go#L326-L343

I have discovered the blockmanager.Stop() never really exits because the done channel has no writes only a blocking read.

dmigwi commented 1 year ago

Actually looking at the code again, I think it works just fine.

I will continue debugging my crash above until I understand why despite closing the chain service some of its goroutines are running in the background.