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

lightningnetwork / lnd / 12583319996

02 Jan 2025 01:38PM UTC coverage: 57.522% (-1.1%) from 58.598%
12583319996

Pull #9361

github

starius
fn/ContextGuard: use context.AfterFunc to wait

Simplifies context cancellation handling by using context.AfterFunc instead of a
goroutine to wait for context cancellation. This approach avoids the overhead of
a goroutine during the waiting period.

For ctxQuitUnsafe, since g.quit is closed only in the Quit method (which also
cancels all associated contexts), waiting on context cancellation ensures the
same behavior without unnecessary dependency on g.quit.

Added a test to ensure that the Create method does not launch any goroutines.
Pull Request #9361: fn: optimize context guard

102587 of 178344 relevant lines covered (57.52%)

24734.33 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