fix: bug with close setting of idle timeout (#775)

Signed-off-by: sjcsjc123 <1401189096@qq.com>
This commit is contained in:
SJC
2024-01-22 13:44:51 +08:00
committed by GitHub
parent 879192cf99
commit 90f89cf588
3 changed files with 96 additions and 24 deletions

View File

@@ -15,7 +15,6 @@
package configmap
import (
"encoding/json"
"fmt"
"reflect"
"sync/atomic"
@@ -58,7 +57,7 @@ type Global struct {
// Downstream configures the behavior of the downstream connection.
type Downstream struct {
// IdleTimeout limits the time that a connection may be idle and stream idle.
IdleTimeout uint32 `json:"idleTimeout,omitempty"`
IdleTimeout uint32 `json:"idleTimeout"`
// MaxRequestHeadersKb limits the size of request headers allowed.
MaxRequestHeadersKb uint32 `json:"maxRequestHeadersKb,omitempty"`
// ConnectionBufferLimits configures the buffer size limits for connections.
@@ -139,12 +138,19 @@ func compareGlobal(old *Global, new *Global) (Result, error) {
// deepCopyGlobal deep copies the global option.
func deepCopyGlobal(global *Global) (*Global, error) {
newGlobal := NewDefaultGlobalOption()
bytes, err := json.Marshal(global)
if err != nil {
return nil, err
if global.Downstream != nil {
newGlobal.Downstream.IdleTimeout = global.Downstream.IdleTimeout
newGlobal.Downstream.MaxRequestHeadersKb = global.Downstream.MaxRequestHeadersKb
newGlobal.Downstream.ConnectionBufferLimits = global.Downstream.ConnectionBufferLimits
if global.Downstream.Http2 != nil {
newGlobal.Downstream.Http2.MaxConcurrentStreams = global.Downstream.Http2.MaxConcurrentStreams
newGlobal.Downstream.Http2.InitialStreamWindowSize = global.Downstream.Http2.InitialStreamWindowSize
newGlobal.Downstream.Http2.InitialConnectionWindowSize = global.Downstream.Http2.InitialConnectionWindowSize
}
}
err = json.Unmarshal(bytes, newGlobal)
return newGlobal, err
newGlobal.AddXRealIpHeader = global.AddXRealIpHeader
newGlobal.DisableXEnvoyHeaders = global.DisableXEnvoyHeaders
return newGlobal, nil
}
// NewDefaultGlobalOption returns a default global config.

View File

@@ -131,7 +131,7 @@ func Test_deepCopyGlobal(t *testing.T) {
name: "deep copy 2",
global: &Global{
Downstream: &Downstream{
IdleTimeout: 1,
IdleTimeout: 0,
MaxRequestHeadersKb: 9600,
ConnectionBufferLimits: 4096,
Http2: NewDefaultHttp2(),
@@ -141,7 +141,7 @@ func Test_deepCopyGlobal(t *testing.T) {
},
want: &Global{
Downstream: &Downstream{
IdleTimeout: 1,
IdleTimeout: 0,
MaxRequestHeadersKb: 9600,
ConnectionBufferLimits: 4096,
Http2: NewDefaultHttp2(),
@@ -151,20 +151,6 @@ func Test_deepCopyGlobal(t *testing.T) {
},
wantErr: nil,
},
{
name: "deep copy 3",
global: &Global{
Downstream: &Downstream{},
AddXRealIpHeader: true,
DisableXEnvoyHeaders: true,
},
want: &Global{
Downstream: NewDefaultDownstream(),
AddXRealIpHeader: true,
DisableXEnvoyHeaders: true,
},
wantErr: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -203,7 +189,10 @@ func Test_AddOrUpdateHigressConfig(t *testing.T) {
old: NewDefaultHigressConfig(),
new: &HigressConfig{
Downstream: &Downstream{
IdleTimeout: 1,
IdleTimeout: 1,
MaxRequestHeadersKb: defaultMaxRequestHeadersKb,
ConnectionBufferLimits: defaultConnectionBufferLimits,
Http2: NewDefaultHttp2(),
},
AddXRealIpHeader: true,
DisableXEnvoyHeaders: true,

View File

@@ -543,6 +543,83 @@ var ConfigMapGlobalEnvoy = suite.ConformanceTest{
},
},
},
{
name: "close the setting of idle timeout",
higressConfig: &configmap.HigressConfig{
Downstream: &configmap.Downstream{
IdleTimeout: 0,
MaxRequestHeadersKb: 60,
ConnectionBufferLimits: 32768,
Http2: &configmap.Http2{
MaxConcurrentStreams: 100,
InitialStreamWindowSize: 65535,
InitialConnectionWindowSize: 1048576,
},
},
DisableXEnvoyHeaders: true,
AddXRealIpHeader: true,
},
envoyAssertion: []envoy.Assertion{
{
Path: "configs.#.dynamic_route_configs.#.route_config",
CheckType: envoy.CheckTypeExist,
TargetNamespace: "higress-system",
ExpectEnvoyConfig: map[string]interface{}{
"request_headers_to_add": []interface{}{
map[string]interface{}{
"append": false,
"header": map[string]interface{}{
"key": "x-real-ip",
"value": "%REQ(X-ENVOY-EXTERNAL-ADDRESS)%",
},
},
},
},
},
{
Path: "configs.#.dynamic_listeners.#.active_state.listener.filter_chains.#.filters.#.typed_config",
CheckType: envoy.CheckTypeExist,
TargetNamespace: "higress-system",
ExpectEnvoyConfig: map[string]interface{}{
"@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager",
"stat_prefix": "outbound_0.0.0.0_80",
},
},
{
Path: "configs.#.dynamic_listeners.#.active_state.listener.filter_chains.#.filters.#.typed_config.http_filters",
CheckType: envoy.CheckTypeMatch,
TargetNamespace: "higress-system",
ExpectEnvoyConfig: map[string]interface{}{
"name": "envoy.filters.http.router",
"typed_config": map[string]interface{}{
"@type": "type.googleapis.com/envoy.extensions.filters.http.router.v3.Router",
"suppress_envoy_headers": true,
},
},
},
{
Path: "configs.#.dynamic_listeners.#.active_state.listener",
CheckType: envoy.CheckTypeExist,
TargetNamespace: "higress-system",
ExpectEnvoyConfig: map[string]interface{}{
"per_connection_buffer_limit_bytes": 32768,
},
},
{
Path: "configs.#.dynamic_listeners.#.active_state.listener.filter_chains.#.filters.#.typed_config",
CheckType: envoy.CheckTypeExist,
TargetNamespace: "higress-system",
ExpectEnvoyConfig: map[string]interface{}{
"max_concurrent_streams": 100,
"initial_stream_window_size": 65535,
"initial_connection_window_size": 1048576,
"stream_idle_timeout": "0s",
"max_request_headers_kb": 60,
"idle_timeout": "0s",
},
},
},
},
}
t.Run("ConfigMap Global Envoy", func(t *testing.T) {