arsyncer icon indicating copy to clipboard operation
arsyncer copied to clipboard

Closing syncer causes panics

Open janekolszak opened this issue 2 years ago • 6 comments

Hi! Calling Close() closes internal channels, but it doesn't prevent sends on those internal channels. Because of that I randomly see:

panic: send on closed channel

goroutine 68 [running]:
github.com/everFinance/arsyncer.(*Syncer).pollingBlock(0xc000178180)
        /home/jan/work/redstone/syncer/.gopath~/pkg/mod/github.com/ever!finance/[email protected]/syncer.go:138 +0x506
created by github.com/everFinance/arsyncer.(*Syncer).Run
        /home/jan/work/redstone/syncer/.gopath~/pkg/mod/github.com/ever!finance/[email protected]/syncer.go:83 +0x97

janekolszak avatar Dec 19 '22 19:12 janekolszak

This is normal, close must be closed channel

zyjblockchain avatar Dec 20 '22 10:12 zyjblockchain

Could you check if arsyncer.Close() was called and avoid writing to a closed channel?

janekolszak avatar Dec 20 '22 10:12 janekolszak

Could you check if arsyncer.Close() was called and avoid writing to a closed channel? It's just an exit process, we don't expect this method to be called during the code run, this method is only applicable inside the program exit process

zyjblockchain avatar Dec 20 '22 12:12 zyjblockchain

You cannot call this method to pause arsyncer, arsyncer does not have a pause function

zyjblockchain avatar Dec 20 '22 12:12 zyjblockchain

Yes, I'm calling Close() only when our service is closing, but this isn't the problem.

The problem is that arsyncer is crashing the service when Close() is called. I call Close() and wait till the SubscribeTx channel is closed. This way I'm sure all transactions pending in the channel get processed before our service is stopped.

Right now I call Close(), arsyncer is crashing and all pending data is lost.

Would you accept a PR?

janekolszak avatar Dec 20 '22 13:12 janekolszak

yes you can push a PR about this problem

zyjblockchain avatar Dec 21 '22 07:12 zyjblockchain