• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 11934293069

20 Nov 2024 01:22PM UTC coverage: 58.969% (+0.02%) from 58.951%
11934293069

Pull #9242

github

aakselrod
testing: get goroutines from sweeper when deadlocked at shutdown
Pull Request #9242: Reapply #8644

50 of 83 new or added lines in 4 files covered. (60.24%)

63 existing lines in 14 files now uncovered.

132805 of 225212 relevant lines covered (58.97%)

19552.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.57
/batch/batch_no_postgres.go
1
//go:build !kvdb_postgres
2
// +build !kvdb_postgres
3

4
package batch
5

6
import (
7
        "github.com/lightningnetwork/lnd/kvdb"
8
)
9

10
// run executes the current batch of requests. If any individual requests fail
11
// alongside others they will be retried by the caller.
12
func (b *batch) run() {
5,095✔
13
        // Clear the batch from its scheduler, ensuring that no new requests are
5,095✔
14
        // added to this batch.
5,095✔
15
        b.clear(b)
5,095✔
16

5,095✔
17
        // If a cache lock was provided, hold it until the this method returns.
5,095✔
18
        // This is critical for ensuring external consistency of the operation,
5,095✔
19
        // so that caches don't get out of sync with the on disk state.
5,095✔
20
        if b.locker != nil {
9,405✔
21
                b.locker.Lock()
4,310✔
22
                defer b.locker.Unlock()
4,310✔
23
        }
4,310✔
24

25
        // Apply the batch until a subset succeeds or all of them fail. Requests
26
        // that fail will be retried individually.
27
        for len(b.reqs) > 0 {
10,190✔
28
                var failIdx = -1
5,095✔
29
                err := kvdb.Update(b.db, func(tx kvdb.RwTx) error {
10,190✔
30
                        for i, req := range b.reqs {
10,191✔
31
                                err := req.Update(tx)
5,096✔
32
                                if err != nil {
5,096✔
NEW
33
                                        failIdx = i
×
NEW
34
                                        return err
×
NEW
35
                                }
×
36
                        }
37
                        return nil
5,095✔
38
                }, func() {
5,095✔
39
                        for _, req := range b.reqs {
10,191✔
40
                                if req.Reset != nil {
9,407✔
41
                                        req.Reset()
4,311✔
42
                                }
4,311✔
43
                        }
44
                })
45

46
                // If a request's Update failed, extract it and re-run the
47
                // batch. The removed request will be retried individually by
48
                // the caller.
49
                if failIdx >= 0 {
5,095✔
NEW
50
                        req := b.reqs[failIdx]
×
NEW
51

×
NEW
52
                        // It's safe to shorten b.reqs here because the
×
NEW
53
                        // scheduler's batch no longer points to us.
×
NEW
54
                        b.reqs[failIdx] = b.reqs[len(b.reqs)-1]
×
NEW
55
                        b.reqs = b.reqs[:len(b.reqs)-1]
×
NEW
56

×
NEW
57
                        // Tell the submitter re-run it solo, continue with the
×
NEW
58
                        // rest of the batch.
×
NEW
59
                        req.errChan <- errSolo
×
NEW
60
                        continue
×
61
                }
62

63
                // None of the remaining requests failed, process the errors
64
                // using each request's OnCommit closure and return the error
65
                // to the requester. If no OnCommit closure is provided, simply
66
                // return the error directly.
67
                for _, req := range b.reqs {
10,191✔
68
                        if req.OnCommit != nil {
9,407✔
69
                                req.errChan <- req.OnCommit(err)
4,311✔
70
                        } else {
5,099✔
71
                                req.errChan <- err
788✔
72
                        }
788✔
73
                }
74

75
                return
5,095✔
76
        }
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc