Add shutdownWg to dcrd notif handler.

This prevents db/dcrd/dcrwallet connections from being closed while the dcrd notification handler is running.
This commit is contained in:
Jamie Holdstock 2021-06-09 10:59:25 +08:00 committed by Jamie Holdstock
parent 36c9f5a562
commit b56dc26558
3 changed files with 9 additions and 3 deletions

View File

@ -42,7 +42,7 @@ VSP will add the ticket to a pool of always-online voting wallets.
## Implementation ## Implementation
vspd is built and tested on go 1.14 and 1.15, making use of the following vspd is built and tested on go 1.15 and 1.16, making use of the following
libraries: libraries:
- [gin-gonic/gin](https://github.com/gin-gonic/gin) webserver. - [gin-gonic/gin](https://github.com/gin-gonic/gin) webserver.

View File

@ -26,7 +26,9 @@ var (
notifierClosed chan struct{} notifierClosed chan struct{}
) )
type NotificationHandler struct{} type NotificationHandler struct {
ShutdownWg *sync.WaitGroup
}
const ( const (
// consistencyInterval is the time period between wallet consistency checks. // consistencyInterval is the time period between wallet consistency checks.
@ -41,6 +43,9 @@ const (
// because that will cause the client to close and no further notifications will // because that will cause the client to close and no further notifications will
// be received until a new connection is established. // be received until a new connection is established.
func (n *NotificationHandler) Notify(method string, params json.RawMessage) error { func (n *NotificationHandler) Notify(method string, params json.RawMessage) error {
n.ShutdownWg.Add(1)
defer n.ShutdownWg.Done()
if method != "blockconnected" { if method != "blockconnected" {
return nil return nil
} }

View File

@ -107,8 +107,9 @@ func run(ctx context.Context) error {
} }
// Create a dcrd client with a blockconnected notification handler. // Create a dcrd client with a blockconnected notification handler.
notifHandler := background.NotificationHandler{ShutdownWg: &shutdownWg}
dcrdWithNotifs := rpc.SetupDcrd(cfg.DcrdUser, cfg.DcrdPass, dcrdWithNotifs := rpc.SetupDcrd(cfg.DcrdUser, cfg.DcrdPass,
cfg.DcrdHost, cfg.dcrdCert, &background.NotificationHandler{}) cfg.DcrdHost, cfg.dcrdCert, &notifHandler)
defer dcrdWithNotifs.Close() defer dcrdWithNotifs.Close()
// Start background process which will continually attempt to reconnect to // Start background process which will continually attempt to reconnect to