Skip to content

Commit b9bd675

Browse files
committed
[release-v2.0] Order mixclient and syncer shutdown
During clean shutdown, signal the mixing client to shutdown first, waiting for it to finish running, before closing the RPC and SPV syncers. Updates the mixing module to a version that supports continuing active mixes before terminating the mixing client. Backport of 11f9b24.
1 parent 9e3cbe0 commit b9bd675

File tree

5 files changed

+92
-54
lines changed

5 files changed

+92
-54
lines changed

chain/sync.go

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,11 @@ func (s *Syncer) Run(ctx context.Context) (err error) {
542542

543543
params := s.wallet.ChainParams()
544544

545+
ntfnCtx, ntfnCtxCancel := context.WithCancel(context.Background())
546+
defer ntfnCtxCancel()
545547
s.notifier = &notifier{
546548
syncer: s,
547-
ctx: ctx,
549+
ctx: ntfnCtx,
548550
closed: make(chan struct{}),
549551
}
550552
addr, err := normalizeAddress(s.opts.Address, s.opts.DefaultPort)
@@ -589,12 +591,12 @@ func (s *Syncer) Run(ctx context.Context) (err error) {
589591
}
590592
opts = append(opts, wsrpc.WithTLSConfig(tc))
591593
}
592-
client, err := wsrpc.Dial(ctx, addr, opts...)
594+
wsClient, err := wsrpc.Dial(ctx, addr, opts...)
593595
if err != nil {
594596
return err
595597
}
596-
defer client.Close()
597-
s.rpc = dcrd.New(client)
598+
defer wsClient.Close()
599+
s.rpc = dcrd.New(wsClient)
598600

599601
// Verify that the server is running on the expected network.
600602
var netID wire.CurrencyNet
@@ -723,10 +725,27 @@ func (s *Syncer) Run(ctx context.Context) (err error) {
723725
return err
724726
}
725727

728+
defer func() {
729+
ntfnCtxCancel()
730+
731+
select {
732+
case <-ctx.Done():
733+
wsClient.Close()
734+
default:
735+
}
736+
737+
// Wait for notifications to finish before returning
738+
<-s.notifier.closed
739+
}()
740+
741+
// Ensure wallet.Run cleanly finishes/is canceled first when outer
742+
// context is canceled.
743+
walletCtx, walletCtxCancel := context.WithCancel(context.Background())
744+
defer walletCtxCancel()
726745
g.Go(func() error {
727746
// Run wallet background goroutines (currently, this just runs
728747
// mixclient).
729-
return s.wallet.Run(ctx)
748+
return s.wallet.Run(walletCtx)
730749
})
731750

732751
// Request notifications for mixing messages.
@@ -739,18 +758,13 @@ func (s *Syncer) Run(ctx context.Context) (err error) {
739758

740759
log.Infof("Blockchain sync completed, wallet ready for general usage.")
741760

742-
// Wait for notifications to finish before returning
743-
defer func() {
744-
<-s.notifier.closed
745-
}()
746-
747761
g.Go(func() error {
748762
select {
749763
case <-ctx.Done():
750-
client.Close()
764+
walletCtxCancel()
751765
return ctx.Err()
752-
case <-client.Done():
753-
return client.Err()
766+
case <-wsClient.Done():
767+
return wsClient.Err()
754768
}
755769
})
756770
return g.Wait()

dcrwallet.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,10 @@ func spvLoop(ctx context.Context, w *wallet.Wallet) {
553553
for {
554554
err := syncer.Run(ctx)
555555
if done(ctx) {
556+
loggers.SyncLog.Infof("SPV synchronization stopped")
556557
return
557558
}
558-
log.Errorf("SPV synchronization ended: %v", err)
559+
loggers.SyncLog.Errorf("SPV synchronization stopped: %v", err)
559560
}
560561
}
561562

@@ -590,7 +591,11 @@ func rpcSyncLoop(ctx context.Context, w *wallet.Wallet) {
590591
syncer := chain.NewSyncer(w, rpcOptions)
591592
err := syncer.Run(ctx)
592593
if err != nil {
593-
loggers.SyncLog.Errorf("Wallet synchronization stopped: %v", err)
594+
if errors.Is(err, context.Canceled) || ctx.Err() != nil {
595+
loggers.SyncLog.Infof("RPC synchronization stopped")
596+
return
597+
}
598+
loggers.SyncLog.Errorf("RPC synchronization stopped: %v", err)
594599
select {
595600
case <-ctx.Done():
596601
return

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module decred.org/dcrwallet/v4
33
go 1.20
44

55
require (
6-
decred.org/cspp/v2 v2.3.0
6+
decred.org/cspp/v2 v2.4.0
77
github.com/decred/dcrd/addrmgr/v2 v2.0.4
88
github.com/decred/dcrd/blockchain/stake/v5 v5.0.1
99
github.com/decred/dcrd/blockchain/standalone/v2 v2.2.1
@@ -13,15 +13,15 @@ require (
1313
github.com/decred/dcrd/chaincfg/v3 v3.2.1
1414
github.com/decred/dcrd/connmgr/v3 v3.1.2
1515
github.com/decred/dcrd/crypto/blake256 v1.1.0
16-
github.com/decred/dcrd/crypto/rand v1.0.0
16+
github.com/decred/dcrd/crypto/rand v1.0.1
1717
github.com/decred/dcrd/crypto/ripemd160 v1.0.2
1818
github.com/decred/dcrd/dcrec v1.0.1
1919
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
2020
github.com/decred/dcrd/dcrjson/v4 v4.1.0
2121
github.com/decred/dcrd/dcrutil/v4 v4.0.2
2222
github.com/decred/dcrd/gcs/v4 v4.1.0
2323
github.com/decred/dcrd/hdkeychain/v3 v3.1.2
24-
github.com/decred/dcrd/mixing v0.4.2
24+
github.com/decred/dcrd/mixing v0.5.0
2525
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.3.0
2626
github.com/decred/dcrd/rpcclient/v8 v8.0.1
2727
github.com/decred/dcrd/txscript/v4 v4.1.1
@@ -36,9 +36,9 @@ require (
3636
github.com/jrick/logrotate v1.0.0
3737
github.com/jrick/wsrpc/v2 v2.3.5
3838
go.etcd.io/bbolt v1.3.8
39-
golang.org/x/crypto v0.26.0
40-
golang.org/x/sync v0.8.0
41-
golang.org/x/term v0.23.0
39+
golang.org/x/crypto v0.33.0
40+
golang.org/x/sync v0.11.0
41+
golang.org/x/term v0.29.0
4242
google.golang.org/grpc v1.45.0
4343
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0
4444
google.golang.org/protobuf v1.27.1
@@ -55,8 +55,8 @@ require (
5555
github.com/golang/protobuf v1.5.2 // indirect
5656
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
5757
golang.org/x/net v0.28.0 // indirect
58-
golang.org/x/sys v0.23.0 // indirect
59-
golang.org/x/text v0.17.0 // indirect
58+
golang.org/x/sys v0.30.0 // indirect
59+
golang.org/x/text v0.22.0 // indirect
6060
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
6161
lukechampine.com/blake3 v1.3.0 // indirect
6262
)

go.sum

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
3-
decred.org/cspp/v2 v2.3.0 h1:GC8emJnLbOVAkgBTHK/1wy6o/m0AVsN1r4m1ZnZZWjo=
4-
decred.org/cspp/v2 v2.3.0/go.mod h1:9nO3bfvCheOPIFZw5f6sRQ42CjBFB5RKSaJ9Iq6G4MA=
3+
decred.org/cspp/v2 v2.4.0 h1:whb0YW+UELHJS/UfT5MBXSJXrKUVw5omhgKNhjzYix4=
4+
decred.org/cspp/v2 v2.4.0/go.mod h1:9nO3bfvCheOPIFZw5f6sRQ42CjBFB5RKSaJ9Iq6G4MA=
55
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
66
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
77
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
@@ -43,8 +43,8 @@ github.com/decred/dcrd/container/lru v1.0.0 h1:7foQymtbu18aQWYiY9RnNIeE+kvpiN+fi
4343
github.com/decred/dcrd/container/lru v1.0.0/go.mod h1:vlPwj0l+IzAHhQSsbgQnJgO5Cte78+yI065V+Mc5PRQ=
4444
github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8=
4545
github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
46-
github.com/decred/dcrd/crypto/rand v1.0.0 h1:Ah9Asl36OZt09sGSMbJZuL1HfwGdlC38q/ZUeLDVKRg=
47-
github.com/decred/dcrd/crypto/rand v1.0.0/go.mod h1:coa7BbxSTiKH6esi257plGfMFYuGL4MTbQlLYnOdzpE=
46+
github.com/decred/dcrd/crypto/rand v1.0.1 h1:pYMgDRmRv1z1RNgAAs8izJstm4B+fLFiqGD5btOt2Wg=
47+
github.com/decred/dcrd/crypto/rand v1.0.1/go.mod h1:MsA2XySk/4KpCOYW6vsNYTGuOYRK1wpvulaWCuW7RyI=
4848
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
4949
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
5050
github.com/decred/dcrd/database/v3 v3.0.2 h1:rgP7XNZemTs8ZC7bnTKO8JO79Woj5nq+yQYmB9ry7yM=
@@ -63,8 +63,8 @@ github.com/decred/dcrd/gcs/v4 v4.1.0 h1:tpW7JW53yJZlgNwl/n2NL1b8NxHaIPRUyNuLMkB/
6363
github.com/decred/dcrd/gcs/v4 v4.1.0/go.mod h1:nPTbGM/I3Ihe5KFvUmxZEqQP/jDZQjQ63+WEi/f4lqU=
6464
github.com/decred/dcrd/hdkeychain/v3 v3.1.2 h1:x25WuuE7zM/20EynuVMyOhL0K8BwGBBsexGq8xTiHFA=
6565
github.com/decred/dcrd/hdkeychain/v3 v3.1.2/go.mod h1:FnNJmZ7jqUDeAo6/c/xkQi5cuxh3EWtJeMmW6/Z8lcc=
66-
github.com/decred/dcrd/mixing v0.4.2 h1:mpt2pNIFTI6L1hXrieAWJTQJv5t9WzHcNnhI+tnAG90=
67-
github.com/decred/dcrd/mixing v0.4.2/go.mod h1:VF87lOn41kitgWVOwmXoB4qMYF7+bxItZXyw4JfW3EQ=
66+
github.com/decred/dcrd/mixing v0.5.0 h1:KEWr6ZKuUcnAMsuWyrwpdCuL48OrCkIZbKn5B1V+wCY=
67+
github.com/decred/dcrd/mixing v0.5.0/go.mod h1:264YZ7KgKsjQGwart40E1QiVzPvLiaKkd/T0c8jtzNI=
6868
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.3.0 h1:l0DnCcILTNrpy8APF3FLN312ChpkQaAuW30aC/RgBaw=
6969
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.3.0/go.mod h1:j+kkRPXPJB5S9VFOsx8SQLcU7PTFkPKRc1aCHN4ENzA=
7070
github.com/decred/dcrd/rpcclient/v8 v8.0.1 h1:hd81e4w1KSqvPcozJlnz6XJfWKDNuahgooH/N5E8vOU=
@@ -140,8 +140,8 @@ go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
140140
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
141141
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
142142
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
143-
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
144-
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
143+
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
144+
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
145145
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
146146
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
147147
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@@ -161,21 +161,21 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
161161
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
162162
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
163163
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
164-
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
165-
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
164+
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
165+
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
166166
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
167167
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
168168
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
169169
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
170170
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
171171
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
172-
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
173-
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
174-
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
175-
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
172+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
173+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
174+
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
175+
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
176176
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
177-
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
178-
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
177+
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
178+
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
179179
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
180180
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
181181
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=

spv/sync.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func (s *Syncer) setRequiredHeight(tipHeight int32) {
321321
}
322322

323323
// Run synchronizes the wallet, returning when synchronization fails or the
324-
// context is cancelled.
324+
// context is canceled.
325325
func (s *Syncer) Run(ctx context.Context) (err error) {
326326
s.doneMu.Lock()
327327
s.done = make(chan struct{})
@@ -367,32 +367,43 @@ func (s *Syncer) Run(ctx context.Context) (err error) {
367367
}
368368

369369
// Start background handlers to read received messages from remote peers
370-
g, ctx := errgroup.WithContext(ctx)
371-
g.Go(func() error { return s.receiveGetData(ctx) })
372-
g.Go(func() error { return s.receiveInv(ctx) })
373-
g.Go(func() error { return s.receiveHeadersAnnouncements(ctx) })
374-
g.Go(func() error { return s.receiveMixMsgs(ctx) })
370+
g, gctx := errgroup.WithContext(context.Background())
371+
g.Go(func() error { return s.receiveGetData(gctx) })
372+
g.Go(func() error { return s.receiveInv(gctx) })
373+
g.Go(func() error { return s.receiveHeadersAnnouncements(gctx) })
374+
g.Go(func() error { return s.receiveMixMsgs(gctx) })
375375
s.lp.AddHandledMessages(p2p.MaskGetData | p2p.MaskInv)
376376

377377
if len(s.persistentPeers) != 0 {
378378
for i := range s.persistentPeers {
379379
raddr := s.persistentPeers[i]
380-
g.Go(func() error { return s.connectToPersistent(ctx, raddr) })
380+
g.Go(func() error { return s.connectToPersistent(gctx, raddr) })
381381
}
382382
} else {
383-
g.Go(func() error { return s.connectToCandidates(ctx) })
383+
g.Go(func() error { return s.connectToCandidates(gctx) })
384384
}
385385

386-
g.Go(func() error { return s.handleMempool(ctx) })
386+
g.Go(func() error { return s.handleMempool(gctx) })
387387

388388
s.wallet.SetNetworkBackend(s)
389389
defer s.wallet.SetNetworkBackend(nil)
390390

391+
// Ensure initial sync and wallet.Run cleanly finish/are canceled
392+
// first when outer context is canceled.
393+
walletCtx, walletCtxCancel := context.WithCancel(context.Background())
394+
go func() {
395+
select {
396+
case <-ctx.Done():
397+
case <-gctx.Done():
398+
}
399+
walletCtxCancel()
400+
}()
401+
391402
// Perform the initial startup sync.
392403
g.Go(func() error {
393404
// First step: fetch missing CFilters.
394405
progress := make(chan wallet.MissingCFilterProgress, 1)
395-
go s.wallet.FetchMissingCFiltersWithProgress(ctx, s, progress)
406+
go s.wallet.FetchMissingCFiltersWithProgress(walletCtx, s, progress)
396407

397408
log.Debugf("Fetching missing CFilters...")
398409
s.fetchMissingCfiltersStart()
@@ -408,14 +419,14 @@ func (s *Syncer) Run(ctx context.Context) (err error) {
408419
// Next: fetch headers and cfilters up to mainchain tip.
409420
s.fetchHeadersStart()
410421
log.Debugf("Fetching headers and CFilters...")
411-
err = s.initialSyncHeaders(ctx)
422+
err = s.initialSyncHeaders(walletCtx)
412423
if err != nil {
413424
return err
414425
}
415426
s.fetchHeadersFinished()
416427

417428
// Finally: Perform the initial rescan over the received blocks.
418-
err = s.initialSyncRescan(ctx)
429+
err = s.initialSyncRescan(walletCtx)
419430
if err != nil {
420431
return err
421432
}
@@ -425,10 +436,18 @@ func (s *Syncer) Run(ctx context.Context) (err error) {
425436
return nil
426437
})
427438

428-
// Run wallet background goroutines (currently, this just runs
429-
// mixclient).
430439
g.Go(func() error {
431-
return s.wallet.Run(ctx)
440+
// Run wallet background goroutines (currently, this just runs
441+
// mixclient).
442+
err := s.wallet.Run(walletCtx)
443+
if err != nil {
444+
return err
445+
}
446+
447+
// If gctx has not yet been canceled, do so here now.
448+
// walletCtx is canceled after either ctx or gctx is canceled.
449+
<-walletCtx.Done()
450+
return walletCtx.Err()
432451
})
433452

434453
// Wait until cancellation or a handler errors.

0 commit comments

Comments
 (0)