• 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

45.45
/lncfg/rpcmiddleware.go
1
package lncfg
2

3
import (
4
        "fmt"
5
        "time"
6
)
7

8
const (
9
        // defaultRPCMiddlewareTimeout is the time after which a request sent to
10
        // a gRPC interception middleware times out. This value is chosen very
11
        // low since in a worst case scenario that time is added to a request's
12
        // full duration twice (request and response interception) if a
13
        // middleware is very slow.
14
        defaultRPCMiddlewareTimeout = 2 * time.Second
15
)
16

17
// RPCMiddleware holds the configuration for RPC interception middleware.
18
//
19
//nolint:ll
20
type RPCMiddleware struct {
21
        Enable           bool          `long:"enable" description:"Enable the RPC middleware interceptor functionality."`
22
        InterceptTimeout time.Duration `long:"intercepttimeout" description:"Time after which a RPC middleware intercept request will time out and return an error if it hasn't yet received a response."`
23
        Mandatory        []string      `long:"addmandatory" description:"Add the named middleware to the list of mandatory middlewares. All RPC requests are blocked/denied if any of the mandatory middlewares is not registered. Can be specified multiple times."`
24
}
25

26
// Validate checks the values configured for the RPC middleware.
27
func (r *RPCMiddleware) Validate() error {
×
28
        if r.InterceptTimeout < 0 {
×
29
                return fmt.Errorf("RPC middleware intercept timeout cannot " +
×
30
                        "be negative")
×
31
        }
×
32

33
        return nil
×
34
}
35

36
// DefaultRPCMiddleware returns the default values for the RPC interception
37
// middleware configuration.
38
func DefaultRPCMiddleware() *RPCMiddleware {
1✔
39
        return &RPCMiddleware{
1✔
40
                InterceptTimeout: defaultRPCMiddlewareTimeout,
1✔
41
        }
1✔
42
}
1✔
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