Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lntest: set ReadHeaderTimeout for http client #7715

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ const (
// client should wait before sending a keepalive ping.
defaultGrpcClientPingMinWait = 5 * time.Second

// defaultHTTPHeaderTimeout is the default timeout for HTTP requests.
DefaultHTTPHeaderTimeout = 5 * time.Second

// BitcoinChainName is a string that represents the Bitcoin blockchain.
BitcoinChainName = "bitcoin"

Expand Down Expand Up @@ -492,6 +495,10 @@ type Config struct {
// Dev specifies configs used for integration tests, which is always
// empty if not built with `integration` flag.
Dev *lncfg.DevConfig `group:"dev" namespace:"dev"`

// HTTPHeaderTimeout is the maximum duration that the server will wait
// before timing out reading the headers of an HTTP request.
HTTPHeaderTimeout time.Duration `long:"http-header-timeout" description:"The maximum duration that the server will wait before timing out reading the headers of an HTTP request."`
yyforyongyu marked this conversation as resolved.
Show resolved Hide resolved
guggero marked this conversation as resolved.
Show resolved Hide resolved
}

// GRPCConfig holds the configuration options for the gRPC server.
Expand Down Expand Up @@ -694,7 +701,8 @@ func DefaultConfig() Config {
ServerPingTimeout: defaultGrpcServerPingTimeout,
ClientPingMinWait: defaultGrpcClientPingMinWait,
},
WtClient: lncfg.DefaultWtClientCfg(),
WtClient: lncfg.DefaultWtClientCfg(),
HTTPHeaderTimeout: DefaultHTTPHeaderTimeout,
}
}

Expand Down
17 changes: 11 additions & 6 deletions docs/release-notes/release-notes-0.18.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
- [Functional Updates](#functional-updates)
- [RPC Updates](#rpc-updates)
- [lncli Updates](#lncli-updates)
- [Code Health](#code-health)
guggero marked this conversation as resolved.
Show resolved Hide resolved
- [Breaking Changes](#breaking-changes)
- [Performance Improvements](#performance-improvements)
- [Technical and Architectural Updates](#technical-and-architectural-updates)
- [BOLT Spec Updates](#bolt-spec-updates)
- [Testing](#testing)
- [Database](#database)
- [Code Health](#code-health)
- [Tooling and Documentation](#tooling-and-documentation)
- [Technical and Architectural Updates](#technical-and-architectural-updates)
- [BOLT Spec Updates](#bolt-spec-updates)
- [Testing](#testing)
- [Database](#database)
- [Code Health](#code-health-1)
- [Tooling and Documentation](#tooling-and-documentation)
- [Contributors (Alphabetical Order)](#contributors-alphabetical-order)

# Bug Fixes

Expand All @@ -36,6 +38,8 @@
and payment to blinded paths has been added via the `QueryRoutes` (and
SendToRouteV2) APIs. This functionality is surfaced in `lncli queryroutes`
where the required flags are tagged with `(blinded paths)`.
* A new config value,
[http-header-timeout](https://github.com/lightningnetwork/lnd/pull/7715), is added so users can specify the amount of time the http server will wait for a request to complete before closing the connection. The default value is 5 seconds.

## RPC Additions
## lncli Additions
Expand Down Expand Up @@ -75,6 +79,7 @@

# Contributors (Alphabetical Order)

* Amin Bashiri
* Andras Banki-Horvath
* Carla Kirk-Cohen
* Elle Mouton
Expand Down
4 changes: 3 additions & 1 deletion lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg,
pprofServer := &http.Server{
Addr: cfg.Profile,
Handler: pprofMux,
ReadHeaderTimeout: 5 * time.Second,
ReadHeaderTimeout: cfg.HTTPHeaderTimeout,
}

// Shut the server down when lnd is shutting down.
Expand Down Expand Up @@ -271,6 +271,8 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg,
LetsEncryptListen: cfg.LetsEncryptListen,

DisableRestTLS: cfg.DisableRestTLS,

HTTPHeaderTimeout: cfg.HTTPHeaderTimeout,
}
tlsManager := NewTLSManager(tlsManagerCfg)
serverOpts, restDialOpts, restListen, cleanUp,
Expand Down
6 changes: 4 additions & 2 deletions lntest/fee_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"
"testing"

"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/lntest/node"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -81,8 +82,9 @@ func NewFeeService(t *testing.T) *FeeService {
mux.HandleFunc("/fee-estimates.json", f.handleRequest)

f.srv = &http.Server{
Addr: listenAddr,
Handler: mux,
Addr: listenAddr,
Handler: mux,
ReadHeaderTimeout: lnd.DefaultHTTPHeaderTimeout,
}

return &f
Expand Down
3 changes: 3 additions & 0 deletions sample-lnd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@
; intelligence services.
; color=#3399FF

; The maximum duration that the server will wait before timing out reading
; the headers of an HTTP request.
; http-header-timeout=5s

[prometheus]

Expand Down
7 changes: 3 additions & 4 deletions tls_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ var (
// - `-----BEGIN PRIVATE KEY-----` (PKCS8).
// - `-----BEGIN EC PRIVATE KEY-----` (SEC1/rfc5915, the legacy format).
privateKeyPrefix = []byte("-----BEGIN ")

// letsEncryptTimeout sets a timeout for the Lets Encrypt server.
letsEncryptTimeout = 5 * time.Second
yyforyongyu marked this conversation as resolved.
Show resolved Hide resolved
)

// TLSManagerCfg houses a set of values and methods that is passed to the
Expand All @@ -61,6 +58,8 @@ type TLSManagerCfg struct {
LetsEncryptListen string

DisableRestTLS bool

HTTPHeaderTimeout time.Duration
}

// TLSManager generates/renews a TLS cert/key pair when needed. When required,
Expand Down Expand Up @@ -424,7 +423,7 @@ func (t *TLSManager) setUpLetsEncrypt(certData *tls.Certificate,
srv := &http.Server{
Addr: t.cfg.LetsEncryptListen,
Handler: manager.HTTPHandler(nil),
ReadHeaderTimeout: letsEncryptTimeout,
ReadHeaderTimeout: t.cfg.HTTPHeaderTimeout,
}
shutdownCompleted := make(chan struct{})
cleanUp = func() {
Expand Down