mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
les: stop ODR retrievals at shutdown
This commit is contained in:
parent
89860f4197
commit
e9b9945242
2 changed files with 7 additions and 4 deletions
|
|
@ -64,7 +64,7 @@ type Msg struct {
|
||||||
|
|
||||||
// Retrieve tries to fetch an object from the LES network.
|
// Retrieve tries to fetch an object from the LES network.
|
||||||
// If the network retrieval was successful, it stores the object in local db.
|
// If the network retrieval was successful, it stores the object in local db.
|
||||||
func (self *LesOdr) Retrieve(ctx context.Context, req light.OdrRequest) (err error) {
|
func (odr *LesOdr) Retrieve(ctx context.Context, req light.OdrRequest) (err error) {
|
||||||
lreq := LesRequest(req)
|
lreq := LesRequest(req)
|
||||||
|
|
||||||
reqID := genReqID()
|
reqID := genReqID()
|
||||||
|
|
@ -84,9 +84,9 @@ func (self *LesOdr) Retrieve(ctx context.Context, req light.OdrRequest) (err err
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = self.retriever.retrieve(ctx, reqID, rq, func(p distPeer, msg *Msg) error { return lreq.Validate(self.db, msg) }); err == nil {
|
if err = odr.retriever.retrieve(ctx, reqID, rq, func(p distPeer, msg *Msg) error { return lreq.Validate(odr.db, msg) }, odr.stop); err == nil {
|
||||||
// retrieved from network, store in db
|
// retrieved from network, store in db
|
||||||
req.StoreResult(self.db)
|
req.StoreResult(odr.db)
|
||||||
} else {
|
} else {
|
||||||
log.Debug("Failed to retrieve data from network", "err", err)
|
log.Debug("Failed to retrieve data from network", "err", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -111,12 +112,14 @@ func newRetrieveManager(peers *peerSet, dist *requestDistributor, serverPool pee
|
||||||
// that is delivered through the deliver function and successfully validated by the
|
// that is delivered through the deliver function and successfully validated by the
|
||||||
// validator callback. It returns when a valid answer is delivered or the context is
|
// validator callback. It returns when a valid answer is delivered or the context is
|
||||||
// cancelled.
|
// cancelled.
|
||||||
func (rm *retrieveManager) retrieve(ctx context.Context, reqID uint64, req *distReq, val validatorFunc) error {
|
func (rm *retrieveManager) retrieve(ctx context.Context, reqID uint64, req *distReq, val validatorFunc, shutdown chan struct{}) error {
|
||||||
sentReq := rm.sendReq(reqID, req, val)
|
sentReq := rm.sendReq(reqID, req, val)
|
||||||
select {
|
select {
|
||||||
case <-sentReq.stopCh:
|
case <-sentReq.stopCh:
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
sentReq.stop(ctx.Err())
|
sentReq.stop(ctx.Err())
|
||||||
|
case <-shutdown:
|
||||||
|
sentReq.stop(fmt.Errorf("Client is shutting down"))
|
||||||
}
|
}
|
||||||
return sentReq.getError()
|
return sentReq.getError()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue