fix(model): shut down index sender faster (#9704)
This commit is contained in:
@@ -233,6 +233,12 @@ func (s *indexHandler) sendIndexTo(ctx context.Context, fset *db.FileSet) error
|
|||||||
batch := db.NewFileInfoBatch(nil)
|
batch := db.NewFileInfoBatch(nil)
|
||||||
var batchError error
|
var batchError error
|
||||||
batch.SetFlushFunc(func(fs []protocol.FileInfo) error {
|
batch.SetFlushFunc(func(fs []protocol.FileInfo) error {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
if len(fs) == 0 {
|
if len(fs) == 0 {
|
||||||
// can't happen, flush is not called with an empty batch
|
// can't happen, flush is not called with an empty batch
|
||||||
panic("bug: flush called with empty batch (race condition?)")
|
panic("bug: flush called with empty batch (race condition?)")
|
||||||
|
|||||||
@@ -354,6 +354,8 @@ func (c *rawConnection) Index(ctx context.Context, idx *Index) error {
|
|||||||
select {
|
select {
|
||||||
case <-c.closed:
|
case <-c.closed:
|
||||||
return ErrClosed
|
return ErrClosed
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
c.idxMut.Lock()
|
c.idxMut.Lock()
|
||||||
@@ -367,6 +369,8 @@ func (c *rawConnection) IndexUpdate(ctx context.Context, idxUp *IndexUpdate) err
|
|||||||
select {
|
select {
|
||||||
case <-c.closed:
|
case <-c.closed:
|
||||||
return ErrClosed
|
return ErrClosed
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
c.idxMut.Lock()
|
c.idxMut.Lock()
|
||||||
@@ -377,6 +381,14 @@ func (c *rawConnection) IndexUpdate(ctx context.Context, idxUp *IndexUpdate) err
|
|||||||
|
|
||||||
// Request returns the bytes for the specified block after fetching them from the connected peer.
|
// Request returns the bytes for the specified block after fetching them from the connected peer.
|
||||||
func (c *rawConnection) Request(ctx context.Context, req *Request) ([]byte, error) {
|
func (c *rawConnection) Request(ctx context.Context, req *Request) ([]byte, error) {
|
||||||
|
select {
|
||||||
|
case <-c.closed:
|
||||||
|
return nil, ErrClosed
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil, ctx.Err()
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
rc := make(chan asyncResult, 1)
|
rc := make(chan asyncResult, 1)
|
||||||
|
|
||||||
c.awaitingMut.Lock()
|
c.awaitingMut.Lock()
|
||||||
|
|||||||
Reference in New Issue
Block a user