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:
parent
36c9f5a562
commit
b56dc26558
@ -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.
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
3
vspd.go
3
vspd.go
@ -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, ¬ifHandler)
|
||||||
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user