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

lightningnetwork / lnd / 12312390362

13 Dec 2024 08:44AM UTC coverage: 57.458% (+8.5%) from 48.92%
12312390362

Pull #9343

github

ellemouton
fn: rework the ContextGuard and add tests

In this commit, the ContextGuard struct is re-worked such that the
context that its new main WithCtx method provides is cancelled in sync
with a parent context being cancelled or with it's quit channel being
cancelled. Tests are added to assert the behaviour. In order for the
close of the quit channel to be consistent with the cancelling of the
derived context, the quit channel _must_ be contained internal to the
ContextGuard so that callers are only able to close the channel via the
exposed Quit method which will then take care to first cancel any
derived context that depend on the quit channel before returning.
Pull Request #9343: fn: expand the ContextGuard and add tests

101853 of 177264 relevant lines covered (57.46%)

24972.93 hits per line

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

0.0
/lncfg/pprof.go
1
package lncfg
2

3
import (
4
        "net"
5
        "strconv"
6
)
7

8
// Pprof holds the configuration options for LND's built-in pprof server.
9
//
10
//nolint:ll
11
type Pprof struct {
12
        CPUProfile string `long:"cpuprofile" description:"Write CPU profile to the specified file"`
13

14
        Profile string `long:"profile" description:"Enable HTTP profiling on either a port or host:port"`
15

16
        BlockingProfile int `long:"blockingprofile" description:"Used to enable a blocking profile to be served on the profiling port. This takes a value from 0 to 1, with 1 including every blocking event, and 0 including no events."`
17

18
        MutexProfile int `long:"mutexprofile" description:"Used to Enable a mutex profile to be served on the profiling port. This takes a value from 0 to 1, with 1 including every mutex event, and 0 including no events."`
19
}
20

21
// Validate checks the values configured for the profiler.
22
func (p *Pprof) Validate() error {
×
23
        if p.BlockingProfile > 0 {
×
24
                log.Warn("Blocking profile enabled only useful for " +
×
25
                        "debugging because of significant performance impact")
×
26
        }
×
27

28
        if p.MutexProfile > 0 {
×
29
                log.Warn("Mutex profile enabled only useful for " +
×
30
                        "debugging because of significant performance impact")
×
31
        }
×
32

33
        if p.CPUProfile != "" {
×
34
                log.Warn("CPU profile enabled only useful for " +
×
35
                        "debugging because of significant performance impact")
×
36
        }
×
37

38
        if p.Profile != "" {
×
39
                str := "%v: The profile port must be between 1024 and 65535"
×
40

×
41
                // Try to parse Profile as a host:port.
×
42
                _, hostPort, err := net.SplitHostPort(p.Profile)
×
43
                if err == nil {
×
44
                        // Determine if the port is valid.
×
45
                        profilePort, err := strconv.Atoi(hostPort)
×
46

×
47
                        if err != nil || profilePort < 1024 ||
×
48
                                profilePort > 65535 {
×
49

×
50
                                return &UsageError{Err: mkErr(str, hostPort)}
×
51
                        }
×
52
                } else {
×
53
                        // Try to parse Profile as a port.
×
54
                        profilePort, err := strconv.Atoi(p.Profile)
×
55
                        if err != nil || profilePort < 1024 ||
×
56
                                profilePort > 65535 {
×
57

×
58
                                return &UsageError{Err: mkErr(str, p.Profile)}
×
59
                        }
×
60

61
                        // Since the user just set a port, we will serve
62
                        // debugging information over localhost.
63
                        p.Profile = net.JoinHostPort("127.0.0.1", p.Profile)
×
64
                }
65
        }
66

67
        return nil
×
68
}
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