From ed164e831ecb662f05e4c1c2aa34d977c801a313 Mon Sep 17 00:00:00 2001 From: tobi Date: Mon, 15 Jun 2026 14:50:16 +0200 Subject: [PATCH] [chore] HTTP server/client config stuff (#4861) # Description > If this is a code change, please include a summary of what you've coded, and link to the issue(s) it closes/implements. > > If this is a documentation change, please briefly describe what you've changed and why. Removes unused setting `MaxOpenConnsPerHost`, document http server + client advanced config defaults, set MaxConnsPerHost to default `maxprocs * 10`. ## Checklist Please put an x inside each checkbox to indicate that you've read and followed it: `[ ]` -> `[x]` If this is a documentation change, only the first two checkboxes must be filled (you can delete the others if you want). - [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md). - [x] I/we have not used so-called 'AI' to create the proposed changes. - [x] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat. - [x] I/we have performed a self-review of added code. - [x] I/we have written code that is legible and maintainable by others. - [x] I/we have commented the added code, particularly in hard-to-understand areas. - [x] I/we have made any necessary changes to documentation. - [ ] I/we have added tests that cover new code. - [x] I/we have run tests and they pass locally with the changes. - [x] I/we have run `go fmt ./...` and `golangci-lint run`. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4861 --- cmd/gotosocial/action/server/server.go | 1 - docs/configuration/httpclient.md | 74 +++++++- docs/configuration/httpserver.md | 139 +++++++++++++++ example/config.yaml | 236 ++++++++++++++++++++----- internal/config/config.go | 1 - internal/config/defaults.go | 6 +- internal/config/helpers.gen.go | 41 +---- internal/httpclient/client.go | 16 +- mkdocs.yml | 1 + test/envparsing.sh | 5 +- 10 files changed, 406 insertions(+), 114 deletions(-) create mode 100644 docs/configuration/httpserver.md diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go index 588829d28..016560055 100644 --- a/cmd/gotosocial/action/server/server.go +++ b/cmd/gotosocial/action/server/server.go @@ -253,7 +253,6 @@ func Start(ctx context.Context) error { DisableKeepAlives: config.GetHTTPClientDisableKeepAlives(), MaxIdleConns: config.GetHTTPClientMaxIdleConns(), MaxIdleConnsPerHost: config.GetHTTPClientMaxIdleConnsPerHost(), - MaxOpenConnsPerHost: config.GetHTTPClientMaxOpenConnsPerHost(), MaxConnsPerHost: config.GetHTTPClientMaxConnsPerHost(), IdleConnTimeout: config.GetHTTPClientIdleConnTimeout(), TLSHandshakeTimeout: config.GetHTTPClientTLSHandshakeTimeout(), diff --git a/docs/configuration/httpclient.md b/docs/configuration/httpclient.md index 2c16c413b..8c9c81bd1 100644 --- a/docs/configuration/httpclient.md +++ b/docs/configuration/httpclient.md @@ -9,15 +9,14 @@ # Settings for OUTGOING http client connections used by GoToSocial to make # requests to remote resources (status GETs, media GETs, inbox POSTs, etc). - http-client: # Duration. Timeout to use for outgoing HTTP requests. If the timeout # is exceeded, the connection to the remote server will be dropped. # A value of 0s indicates no timeout: this is not advised! - # Examples: ["5s", "10s", "0s"] - # Default: "10s" - timeout: "10s" + # Examples: ["5s", "30s", "0s"] + # Default: "1m" + timeout: "1m" ######################################## #### RESERVED IP RANGE EXCEPTIONS ###### @@ -74,4 +73,71 @@ http-client: # # Default: false insecure-outgoing: false + + ########################################################################## + ##### Options passed directly to the HTTP client's http.Transport{}: ##### + ########################################################################## + + # NOTE: all of the below are internal HTTP client configuration flags, + # you should not uncomment + tweak these unless you know what you're doing! + # + # The commented-out values are set to the sensible values GtS uses by default. + + # DisableKeepAlives, if true, disables HTTP keep-alives and will only use the + # connection to the server for a single HTTP request. + # + # This is unrelated to the similarly named TCP keep-alives. + # + # Default: false + #disable-keep-alives: false + + # MaxConnsPerHost optionally limits the total number of connections per host, + # including connections in the dialing, active, and idle states. On limit + # violation, dials will block. + # + # Default: 6 + #max-conns-per-host: 6 + + # MaxIdleConns controls the maximum number of idle (keep-alive) connections across + # all hosts. Zero means no limit. + # + # Default: 0 (no limit) + #max-idle-conns: 0 + + # MaxIdleConnsPerHost, if non-zero, controls the maximum idle (keep-alive) + # connections to keep per-host. If zero, DefaultMaxIdleConnsPerHost (2) is used. + # + # Default: 0 (use built-in default 2) + #max-idle-conns-per-host: 0 + + # IdleConnTimeout is the maximum amount of time an idle (keep-alive) connection + # will remain idle before closing itself. Zero means no limit. + # + # Default: 5 minutes + #idle-conn-timeout: "5 minutes" + + # TLSHandshakeTimeout specifies the maximum amount of time to wait for a TLS + # handshake. Zero means no timeout. + # + # Default: 0 (no limit) + #tls-handshake-timeout: "0" + + # ResponseHeaderTimeout, if non-zero, specifies the amount of time to wait for a + # server's response headers after fully writing the request (including its body, if any). + # This time does not include the time to read the response body. + # + # Default: 0 (no limit) + #response-header-timeout: "0" + + # ReadBufferSize specifies the size of the read buffer used when reading from the transport. + # If zero, a default (currently 4KB) is used. + # + # Default: 0 (use built-in default 4KB) + #read-buffer-size: "0" + + # WriteBufferSize specifies the size of the write buffer used when writing to the transport. + # If zero, a default (currently 4KB) is used. + # + # Default: 0 (use built-in default 4KB) + #write-buffer-size: "0" ``` diff --git a/docs/configuration/httpserver.md b/docs/configuration/httpserver.md new file mode 100644 index 000000000..4d9c299ce --- /dev/null +++ b/docs/configuration/httpserver.md @@ -0,0 +1,139 @@ +# HTTP Server + +## Settings + +```yaml +################################ +##### HTTP SERVER SETTINGS ##### +################################ + +# Settings for INCOMING http server connections received by GoToSocial. +# +# WARNING: all of the below are internal HTTP server configuration flags, +# you should not uncomment + tweak these unless you know what you're doing! +# They are set to sensible defaults and you shouldn't need to change them. +http-server: + + ####################################################################### + ##### Options passed directly to our HTTP router's gin.Engine{}: ##### + ####################################################################### + + # MaxMultipartMemory value of 'maxMemory' param that is given to + # http.Request's ParseMultipartForm method call. + # + # Default: 40MiB + #max-multipart-memory: "40MiB" + + # Enable h2c (http2 without TLS). + # + # May be useful if your reverse proxy supports connecting to GoToSocial via HTTP2. + # + # Default: false + #use-h2c: false + + ####################################################################### + ##### Options passed directly to our base http.Server{} instance: ##### + ####################################################################### + + # ReadTimeout is the maximum duration for reading the entire request, + # including the body. A zero or negative value means there will be no timeout. + # + # Because ReadTimeout does not let Handlers make per-request decisions on + # each request body's acceptable deadline or upload rate, most users will prefer + # to use ReadHeaderTimeout. It is valid to use them both. + # + # Default: 60s + #read-timeout: "60s" + + # ReadHeaderTimeout is the amount of time allowed to read request headers. + # The connection's read deadline is reset after reading the headers and the + # Handler can decide what is considered too slow for the body. If zero, the + # value of ReadTimeout is used. If negative, or if zero and ReadTimeout is + # zero or negative, there is no timeout. + # + # Default: 0 (use read-timeout duration). + #read-header-timeout: "0" + + # WriteTimeout is the maximum duration before timing out writes of the response. + # It is reset whenever a new request's header is read. Like ReadTimeout, it does + # not let Handlers make decisions on a per-request basis. A zero or negative value + # means there will be no timeout. + # + # Default: 30s + #write-timeout: "30s" + + # IdleTimeout is the maximum amount of time to wait for the next request when + # keep-alives are enabled. If zero, the value of ReadTimeout is used. If negative, + # or if zero and ReadTimeout is zero or negative, there is no timeout. + # + # Default: 30s + #idle-timeout: "30s" + + # MaxHeaderBytes controls the maximum number of bytes the server will read parsing + # the request header's keys and values, including the request line. It does not limit + # the size of the request body. If zero, DefaultMaxHeaderBytes is used. + # + # Default: 0 (use built-in default 1048576, ie., 1 mebibyte) + #max-header-bytes: "0" + + ############################################################################ + ##### Options passed directly to our HTTP server's http.HTTP2Config{}: ##### + ############################################################################ + + # MaxConcurrentStreams optionally specifies the number of concurrent streams that a + # peer may have open at a time. If zero, MaxConcurrentStreams defaults to at least 100. + # + # Default: 0 (at least 100) + #max-concurrent-streams: "0" + + # MaxDecoderHeaderTableSize optionally specifies an upper limit for the size of the header + # compression table used for decoding headers sent by the peer. A valid value is less than + # 4MiB. If zero or invalid, a default value is used. + # + # Default: 0 (use built-in default 4096, ie., 4 kibibytes) + #max-decoder-header-table-size: "0" + + # MaxEncoderHeaderTableSize optionally specifies an upper limit for the header compression + # table used for sending headers to the peer. A valid value is less than 4MiB. If zero or + # invalid, a default value is used. + # + # Default: 0 (use built-in default 4096, ie., 4 kibibytes) + #max-encoder-header-table-size: "0" + + # MaxReadFrameSize optionally specifies the largest frame this endpoint is willing to read. + # A valid value is between 16KiB and 16MiB, inclusive. If zero or invalid, a default value is used. + # + # Default: 0 (use built-in default 1048576, ie., 1 mebibyte) + #max-read-frame-size: "0" + + # MaxReceiveBufferPerConnection is the maximum size of the flow control window for data received + # on a connection. A valid value is at least 64KiB and less than 4MiB. If invalid, a default value + # is used. + # + # Default: 0 (use built-in default 1048576, ie., 1 mebibyte) + #max-receive-buffer-per-connection: "0" + + # MaxReceiveBufferPerStream is the maximum size of the flow control window for data received on a + # stream (request). A valid value is less than 4MiB. If zero or invalid, a default value is used. + # + # Default: 0 (use built-in default 1048576, ie., 1 mebibyte) + #max-receive-buffer-per-stream: "0" + + # SendPingTimeout is the timeout after which a health check using a ping frame will be carried out + # if no frame is received on a connection. If zero, no health check is performed. + # + # Default: 0 + #send-ping-timeout: "0" + + # PingTimeout is the timeout after which a connection will be closed if a response to a ping is not + # received. If zero, a default of 15 seconds is used. + # + # Default: 0 (use built-in default 15s) + #ping-timeout: "0" + + # WriteByteTimeout is the timeout after which a connection will be closed if no data can be written to it. + # The timeout begins when data is available to write, and is extended whenever any bytes are written. + # + # Default: 0 + #write-byte-timeout: "0" +``` diff --git a/example/config.yaml b/example/config.yaml index d34d6cb45..2f6ff86fc 100644 --- a/example/config.yaml +++ b/example/config.yaml @@ -1226,8 +1226,8 @@ http-client: # is exceeded, the connection to the remote server will be dropped. # A value of 0s indicates no timeout: this is not advised! # Examples: ["5s", "30s", "0s"] - # Default: "30s" - timeout: "30s" + # Default: "1m" + timeout: "1m" ######################################## #### RESERVED IP RANGE EXCEPTIONS ###### @@ -1284,63 +1284,207 @@ http-client: # # Default: false insecure-outgoing: false + + ########################################################################## + ##### Options passed directly to the HTTP client's http.Transport{}: ##### + ########################################################################## # NOTE: all of the below are internal HTTP client configuration flags, - # you should not tweak these unless you know what you're doing! + # you should not uncomment + tweak these unless you know what you're doing! # - # The default value for any of these options is to leave it unset. - # if you must know what the default value actually is, please look - # in the appropriate Go library referenced by its type below. + # The commented-out values are set to the sensible values GtS uses by default. + + # DisableKeepAlives, if true, disables HTTP keep-alives and will only use the + # connection to the server for a single HTTP request. # - # Options passed directly to the HTTP client's http.Transport{}: + # This is unrelated to the similarly named TCP keep-alives. + # + # Default: false #disable-keep-alives: false - #max-idle-conns: 10 - #max-idle-conns-per-host: 10 - #max-open-conns-per-host: 10 - #max-conns-per-host: 10 - #idle-conn-timeout: "30s" - #tls-handshake-timeout: "30s" - #response-header-timeout: "30s" - #read-buffer-size: "16KiB" - #write-buffer-size: "16KiB" + + # MaxConnsPerHost optionally limits the total number of connections per host, + # including connections in the dialing, active, and idle states. On limit + # violation, dials will block. + # + # Default: 6 + #max-conns-per-host: 6 + + # MaxIdleConns controls the maximum number of idle (keep-alive) connections across + # all hosts. Zero means no limit. + # + # Default: 0 (no limit) + #max-idle-conns: 0 + + # MaxIdleConnsPerHost, if non-zero, controls the maximum idle (keep-alive) + # connections to keep per-host. If zero, DefaultMaxIdleConnsPerHost (2) is used. + # + # Default: 0 (use built-in default 2) + #max-idle-conns-per-host: 0 + + # IdleConnTimeout is the maximum amount of time an idle (keep-alive) connection + # will remain idle before closing itself. Zero means no limit. + # + # Default: 5 minutes + #idle-conn-timeout: "5 minutes" + + # TLSHandshakeTimeout specifies the maximum amount of time to wait for a TLS + # handshake. Zero means no timeout. + # + # Default: 0 (no limit) + #tls-handshake-timeout: "0" + + # ResponseHeaderTimeout, if non-zero, specifies the amount of time to wait for a + # server's response headers after fully writing the request (including its body, if any). + # This time does not include the time to read the response body. + # + # Default: 0 (no limit) + #response-header-timeout: "0" + + # ReadBufferSize specifies the size of the read buffer used when reading from the transport. + # If zero, a default (currently 4KB) is used. + # + # Default: 0 (use built-in default 4KB) + #read-buffer-size: "0" + + # WriteBufferSize specifies the size of the write buffer used when writing to the transport. + # If zero, a default (currently 4KB) is used. + # + # Default: 0 (use built-in default 4KB) + #write-buffer-size: "0" ################################ ##### HTTP SERVER SETTINGS ##### ################################ -# Settings for INCOMING http server -# connections received by GoToSocial. +# Settings for INCOMING http server connections received by GoToSocial. +# +# WARNING: all of the below are internal HTTP server configuration flags, +# you should not uncomment + tweak these unless you know what you're doing! +# They are set to sensible defaults and you shouldn't need to change them. http-server: - # NOTE: all of the below are internal HTTP server configuration flags, - # you should not tweak these unless you know what you're doing! - # - # The default value for any of these options is to leave it unset. - # if you must know what the default value actually is, please look - # in the appropriate Go library referenced by its type below. - # - # Options passed directly to our HTTP router's gin.Enginer{}: - #max-multipart-memory: "40MiB" - #use-h2c: false - # - # Options passed directly to our base http.Server{} instance: - #read-timeout: "5m" - #read-header-timeout: "30s" - #write-timeout: "10m" - #idle-timeout: "1m" - #max-header-bytes: "16KiB" - # - # Options passed directly to our HTTP server's http.HTTP2Config{}: - #max-concurrent-streams: 30 - #max-decoder-header-table-size: "1MiB" - #max-encoder-header-table-size: "1MiB" - #max-read-frame-size: "1MiB" - #max-receive-buffer-per-connection: "30MiB" - #max-receive-buffer-per-stream: "30MiB" - #send-ping-timeout: "60s" - #ping-timeout: "60s" - #write-byte-timeout: "60s" + ####################################################################### + ##### Options passed directly to our HTTP router's gin.Engine{}: ##### + ####################################################################### + # MaxMultipartMemory value of 'maxMemory' param that is given to + # http.Request's ParseMultipartForm method call. + # + # Default: 40MiB + #max-multipart-memory: "40MiB" + + # Enable h2c (http2 without TLS). + # + # May be useful if your reverse proxy supports connecting to GoToSocial via HTTP2. + # + # Default: false + #use-h2c: false + + ####################################################################### + ##### Options passed directly to our base http.Server{} instance: ##### + ####################################################################### + + # ReadTimeout is the maximum duration for reading the entire request, + # including the body. A zero or negative value means there will be no timeout. + # + # Because ReadTimeout does not let Handlers make per-request decisions on + # each request body's acceptable deadline or upload rate, most users will prefer + # to use ReadHeaderTimeout. It is valid to use them both. + # + # Default: 60s + #read-timeout: "60s" + + # ReadHeaderTimeout is the amount of time allowed to read request headers. + # The connection's read deadline is reset after reading the headers and the + # Handler can decide what is considered too slow for the body. If zero, the + # value of ReadTimeout is used. If negative, or if zero and ReadTimeout is + # zero or negative, there is no timeout. + # + # Default: 0 (use read-timeout duration). + #read-header-timeout: "0" + + # WriteTimeout is the maximum duration before timing out writes of the response. + # It is reset whenever a new request's header is read. Like ReadTimeout, it does + # not let Handlers make decisions on a per-request basis. A zero or negative value + # means there will be no timeout. + # + # Default: 30s + #write-timeout: "30s" + + # IdleTimeout is the maximum amount of time to wait for the next request when + # keep-alives are enabled. If zero, the value of ReadTimeout is used. If negative, + # or if zero and ReadTimeout is zero or negative, there is no timeout. + # + # Default: 30s + #idle-timeout: "30s" + + # MaxHeaderBytes controls the maximum number of bytes the server will read parsing + # the request header's keys and values, including the request line. It does not limit + # the size of the request body. If zero, DefaultMaxHeaderBytes is used. + # + # Default: 0 (use built-in default 1048576, ie., 1 mebibyte) + #max-header-bytes: "0" + + ############################################################################ + ##### Options passed directly to our HTTP server's http.HTTP2Config{}: ##### + ############################################################################ + + # MaxConcurrentStreams optionally specifies the number of concurrent streams that a + # peer may have open at a time. If zero, MaxConcurrentStreams defaults to at least 100. + # + # Default: 0 (at least 100) + #max-concurrent-streams: "0" + + # MaxDecoderHeaderTableSize optionally specifies an upper limit for the size of the header + # compression table used for decoding headers sent by the peer. A valid value is less than + # 4MiB. If zero or invalid, a default value is used. + # + # Default: 0 (use built-in default 4096, ie., 4 kibibytes) + #max-decoder-header-table-size: "0" + + # MaxEncoderHeaderTableSize optionally specifies an upper limit for the header compression + # table used for sending headers to the peer. A valid value is less than 4MiB. If zero or + # invalid, a default value is used. + # + # Default: 0 (use built-in default 4096, ie., 4 kibibytes) + #max-encoder-header-table-size: "0" + + # MaxReadFrameSize optionally specifies the largest frame this endpoint is willing to read. + # A valid value is between 16KiB and 16MiB, inclusive. If zero or invalid, a default value is used. + # + # Default: 0 (use built-in default 1048576, ie., 1 mebibyte) + #max-read-frame-size: "0" + + # MaxReceiveBufferPerConnection is the maximum size of the flow control window for data received + # on a connection. A valid value is at least 64KiB and less than 4MiB. If invalid, a default value + # is used. + # + # Default: 0 (use built-in default 1048576, ie., 1 mebibyte) + #max-receive-buffer-per-connection: "0" + + # MaxReceiveBufferPerStream is the maximum size of the flow control window for data received on a + # stream (request). A valid value is less than 4MiB. If zero or invalid, a default value is used. + # + # Default: 0 (use built-in default 1048576, ie., 1 mebibyte) + #max-receive-buffer-per-stream: "0" + + # SendPingTimeout is the timeout after which a health check using a ping frame will be carried out + # if no frame is received on a connection. If zero, no health check is performed. + # + # Default: 0 + #send-ping-timeout: "0" + + # PingTimeout is the timeout after which a connection will be closed if a response to a ping is not + # received. If zero, a default of 15 seconds is used. + # + # Default: 0 (use built-in default 15s) + #ping-timeout: "0" + + # WriteByteTimeout is the timeout after which a connection will be closed if no data can be written to it. + # The timeout begins when data is available to write, and is extended whenever any bytes are written. + # + # Default: 0 + #write-byte-timeout: "0" ############################# ##### ADVANCED SETTINGS ##### diff --git a/internal/config/config.go b/internal/config/config.go index 8de1e71b4..a0bb422ac 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -237,7 +237,6 @@ type HTTPClientConfiguration struct { DisableKeepAlives bool `name:"disable-keep-alives"` MaxIdleConns int `name:"max-idle-conns"` MaxIdleConnsPerHost int `name:"max-idle-conns-per-host"` - MaxOpenConnsPerHost int `name:"max-open-conns-per-host"` MaxConnsPerHost int `name:"max-conns-per-host"` IdleConnTimeout time.Duration `name:"idle-conn-timeout"` TLSHandshakeTimeout time.Duration `name:"tls-handshake-timeout"` diff --git a/internal/config/defaults.go b/internal/config/defaults.go index 6f3b6f70e..1bdeca151 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -297,13 +297,11 @@ var Defaults = Configuration{ Timeout: time.Minute, TLSInsecureSkipVerify: false, InsecureOutgoing: false, - + MaxConnsPerHost: 6, + IdleConnTimeout: 5 * time.Minute, DisableKeepAlives: false, // default MaxIdleConns: 0, // default MaxIdleConnsPerHost: 0, // default - MaxOpenConnsPerHost: 0, // default - MaxConnsPerHost: 0, // default - IdleConnTimeout: 0, // default TLSHandshakeTimeout: 0, // default ResponseHeaderTimeout: 0, // default ReadBufferSize: 0, // default diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go index 8c80792ef..981eb4707 100644 --- a/internal/config/helpers.gen.go +++ b/internal/config/helpers.gen.go @@ -170,7 +170,6 @@ const ( HTTPClientDisableKeepAlivesFlag = "http-client-disable-keep-alives" HTTPClientMaxIdleConnsFlag = "http-client-max-idle-conns" HTTPClientMaxIdleConnsPerHostFlag = "http-client-max-idle-conns-per-host" - HTTPClientMaxOpenConnsPerHostFlag = "http-client-max-open-conns-per-host" HTTPClientMaxConnsPerHostFlag = "http-client-max-conns-per-host" HTTPClientIdleConnTimeoutFlag = "http-client-idle-conn-timeout" HTTPClientTLSHandshakeTimeoutFlag = "http-client-tls-handshake-timeout" @@ -416,7 +415,6 @@ func (cfg *Configuration) RegisterFlags(flags *pflag.FlagSet) { flags.Bool("http-client-disable-keep-alives", cfg.HTTPClient.DisableKeepAlives, "") flags.Int("http-client-max-idle-conns", cfg.HTTPClient.MaxIdleConns, "") flags.Int("http-client-max-idle-conns-per-host", cfg.HTTPClient.MaxIdleConnsPerHost, "") - flags.Int("http-client-max-open-conns-per-host", cfg.HTTPClient.MaxOpenConnsPerHost, "") flags.Int("http-client-max-conns-per-host", cfg.HTTPClient.MaxConnsPerHost, "") flags.Duration("http-client-idle-conn-timeout", cfg.HTTPClient.IdleConnTimeout, "") flags.Duration("http-client-tls-handshake-timeout", cfg.HTTPClient.TLSHandshakeTimeout, "") @@ -514,7 +512,7 @@ func (cfg *Configuration) RegisterFlags(flags *pflag.FlagSet) { } func (cfg *Configuration) MarshalMap() map[string]any { - cfgmap := make(map[string]any, 245) + cfgmap := make(map[string]any, 244) cfgmap["log-level"] = cfg.LogLevel cfgmap["log-format"] = cfg.LogFormat cfgmap["log-timestamp-format"] = cfg.LogTimestampFormat @@ -651,7 +649,6 @@ func (cfg *Configuration) MarshalMap() map[string]any { cfgmap["http-client-disable-keep-alives"] = cfg.HTTPClient.DisableKeepAlives cfgmap["http-client-max-idle-conns"] = cfg.HTTPClient.MaxIdleConns cfgmap["http-client-max-idle-conns-per-host"] = cfg.HTTPClient.MaxIdleConnsPerHost - cfgmap["http-client-max-open-conns-per-host"] = cfg.HTTPClient.MaxOpenConnsPerHost cfgmap["http-client-max-conns-per-host"] = cfg.HTTPClient.MaxConnsPerHost cfgmap["http-client-idle-conn-timeout"] = cfg.HTTPClient.IdleConnTimeout cfgmap["http-client-tls-handshake-timeout"] = cfg.HTTPClient.TLSHandshakeTimeout @@ -1906,14 +1903,6 @@ func (cfg *Configuration) UnmarshalMap(cfgmap map[string]any) error { } } - if ival, ok := cfgmap["http-client-max-open-conns-per-host"]; ok { - var err error - cfg.HTTPClient.MaxOpenConnsPerHost, err = cast.ToIntE(ival) - if err != nil { - return fmt.Errorf("error casting %#v -> int for 'http-client-max-open-conns-per-host': %w", ival, err) - } - } - if ival, ok := cfgmap["http-client-max-conns-per-host"]; ok { var err error cfg.HTTPClient.MaxConnsPerHost, err = cast.ToIntE(ival) @@ -5162,23 +5151,6 @@ func GetHTTPClientMaxIdleConnsPerHost() int { return global.GetHTTPClientMaxIdle // SetHTTPClientMaxIdleConnsPerHost safely sets the value for global configuration 'HTTPClient.MaxIdleConnsPerHost' field func SetHTTPClientMaxIdleConnsPerHost(v int) { global.SetHTTPClientMaxIdleConnsPerHost(v) } -// GetHTTPClientMaxOpenConnsPerHost safely fetches the Configuration value for state's 'HTTPClient.MaxOpenConnsPerHost' field -func (st *ConfigState) GetHTTPClientMaxOpenConnsPerHost() (v int) { - return st.config.HTTPClient.MaxOpenConnsPerHost -} - -// SetHTTPClientMaxOpenConnsPerHost safely sets the Configuration value for state's 'HTTPClient.MaxOpenConnsPerHost' field -func (st *ConfigState) SetHTTPClientMaxOpenConnsPerHost(v int) { - st.config.HTTPClient.MaxOpenConnsPerHost = v - st.reloadToViper() -} - -// GetHTTPClientMaxOpenConnsPerHost safely fetches the value for global configuration 'HTTPClient.MaxOpenConnsPerHost' field -func GetHTTPClientMaxOpenConnsPerHost() int { return global.GetHTTPClientMaxOpenConnsPerHost() } - -// SetHTTPClientMaxOpenConnsPerHost safely sets the value for global configuration 'HTTPClient.MaxOpenConnsPerHost' field -func SetHTTPClientMaxOpenConnsPerHost(v int) { global.SetHTTPClientMaxOpenConnsPerHost(v) } - // GetHTTPClientMaxConnsPerHost safely fetches the Configuration value for state's 'HTTPClient.MaxConnsPerHost' field func (st *ConfigState) GetHTTPClientMaxConnsPerHost() (v int) { return st.config.HTTPClient.MaxConnsPerHost @@ -7439,17 +7411,6 @@ func flattenConfigMap(cfgmap map[string]any) { } } - for _, key := range [][]string{ - {"http-client", "max-open-conns-per-host"}, - } { - ival, ok := mapGet(cfgmap, key...) - if ok { - cfgmap["http-client-max-open-conns-per-host"] = ival - nestedKeys[key[0]] = struct{}{} - break - } - } - for _, key := range [][]string{ {"http-client", "max-conns-per-host"}, } { diff --git a/internal/httpclient/client.go b/internal/httpclient/client.go index 19f547a9b..b9676d3e1 100644 --- a/internal/httpclient/client.go +++ b/internal/httpclient/client.go @@ -26,7 +26,6 @@ import ( "net" "net/http" "net/netip" - "runtime" "strconv" "strings" "time" @@ -82,9 +81,6 @@ type Config struct { // MaxIdleConnsPerHost: see http.Transport{}.MaxIdleConnsPerHost. MaxIdleConnsPerHost int - // MaxConnsPerHost: see http.Transport{}.MaxOpenConnsPerHost. - MaxOpenConnsPerHost int - // MaxConnsPerHost: see http.Transport{}.MaxConnsPerHost. MaxConnsPerHost int @@ -133,17 +129,6 @@ func New(cfg Config) *Client { Resolver: &net.Resolver{}, } - if cfg.MaxOpenConnsPerHost <= 0 { - // By default base on on GOMAXPROCS. - maxprocs := runtime.GOMAXPROCS(0) - cfg.MaxOpenConnsPerHost = maxprocs * 20 - } - - if cfg.MaxIdleConns <= 0 { - // By default base this value on MaxOpenConns. - cfg.MaxIdleConns = cfg.MaxOpenConnsPerHost * 10 - } - // Protect the dialer // with IP range sanitizer. d.Control = (&Sanitizer{ @@ -172,6 +157,7 @@ func New(cfg Config) *Client { ForceAttemptHTTP2: true, DialContext: d.DialContext, TLSClientConfig: tlsClientConfig, + DisableKeepAlives: cfg.DisableKeepAlives, MaxIdleConns: cfg.MaxIdleConns, MaxIdleConnsPerHost: cfg.MaxIdleConnsPerHost, MaxConnsPerHost: cfg.MaxConnsPerHost, diff --git a/mkdocs.yml b/mkdocs.yml index 67357a2f0..b0efc0cad 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -113,6 +113,7 @@ nav: - "configuration/smtp.md" - "configuration/syslog.md" - "configuration/httpclient.md" + - "configuration/httpserver.md" - "configuration/advanced.md" - "configuration/observability_and_metrics.md" - "Advanced": diff --git a/test/envparsing.sh b/test/envparsing.sh index 968d9842b..f0e783d1e 100755 --- a/test/envparsing.sh +++ b/test/envparsing.sh @@ -122,12 +122,11 @@ EXPECT=$(cat << "EOF" "http-client-allow-ips": [], "http-client-block-ips": [], "http-client-disable-keep-alives": false, - "http-client-idle-conn-timeout": 0, + "http-client-idle-conn-timeout": 300000000000, "http-client-insecure-outgoing": false, - "http-client-max-conns-per-host": 0, + "http-client-max-conns-per-host": 6, "http-client-max-idle-conns": 0, "http-client-max-idle-conns-per-host": 0, - "http-client-max-open-conns-per-host": 0, "http-client-read-buffer-size": "0B", "http-client-response-header-timeout": 0, "http-client-timeout": 60000000000,