From 61bd802f3cb01b6af542dad2c884d61a234eed97 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Tue, 8 Aug 2023 10:07:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/storage_file.go | 3 ++- internal/nodes/http_client_pool_test.go | 5 +++-- internal/nodes/http_request_root.go | 2 +- internal/nodes/node.go | 7 ++++--- internal/nodes/node_panic_arm64.go | 3 +-- internal/utils/expires/list_test.go | 4 ++-- internal/waf/requests/test_request.go | 4 ++++ internal/waf/values/ip_range.go | 2 +- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index 33998c4..d8cc5f3 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -157,6 +157,7 @@ func (this *FileStorage) UpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy) IsFull: false, }) } + this.subDirs = subDirs this.checkDiskSpace() err = newOptions.Init() @@ -482,7 +483,7 @@ func (this *FileStorage) openWriter(key string, expiredAt int64, status int, hea stat, err := os.Stat(cachePath) // 检查两次写入缓存的时间是否过于相近,分片内容不受此限制 - if err == nil && !isPartial && time.Now().Sub(stat.ModTime()) <= 1*time.Second { + if err == nil && !isPartial && time.Since(stat.ModTime()) <= 1*time.Second { // 防止并发连续写入 return nil, ErrFileIsWriting } diff --git a/internal/nodes/http_client_pool_test.go b/internal/nodes/http_client_pool_test.go index fd65e58..210f894 100644 --- a/internal/nodes/http_client_pool_test.go +++ b/internal/nodes/http_client_pool_test.go @@ -1,6 +1,7 @@ package nodes import ( + "context" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "runtime" "testing" @@ -43,7 +44,7 @@ func TestHTTPClientPool_cleanClients(t *testing.T) { Version: 2, Addr: &serverconfigs.NetworkAddressConfig{Host: "127.0.0.1", PortRange: "1234"}, } - err := origin.Init(nil) + err := origin.Init(context.Background()) if err != nil { t.Fatal(err) } @@ -65,7 +66,7 @@ func BenchmarkHTTPClientPool_Client(b *testing.B) { Version: 2, Addr: &serverconfigs.NetworkAddressConfig{Host: "127.0.0.1", PortRange: "1234"}, } - err := origin.Init(nil) + err := origin.Init(context.Background()) if err != nil { b.Fatal(err) } diff --git a/internal/nodes/http_request_root.go b/internal/nodes/http_request_root.go index 7ce763f..7a4377d 100644 --- a/internal/nodes/http_request_root.go +++ b/internal/nodes/http_request_root.go @@ -95,7 +95,7 @@ func (this *HTTPRequest) doRoot() (isBreak bool) { } var filename = strings.Replace(requestPath, "/", Tea.DS, -1) - var filePath = "" + var filePath string if len(filename) > 0 && filename[0:1] == Tea.DS { filePath = rootDir + filename } else { diff --git a/internal/nodes/node.go b/internal/nodes/node.go index c23087a..e045cdf 100644 --- a/internal/nodes/node.go +++ b/internal/nodes/node.go @@ -2,6 +2,7 @@ package nodes import ( "bytes" + "context" "encoding/json" "errors" "github.com/TeaOSLab/EdgeCommon/pkg/configutils" @@ -194,7 +195,7 @@ func (this *Node) Start() { } teaconst.NodeId = nodeConfig.Id teaconst.NodeIdString = types.String(teaconst.NodeId) - err, serverErrors := nodeConfig.Init(nil) + err, serverErrors := nodeConfig.Init(context.Background()) if err != nil { remotelogs.Error("NODE", "init node config failed: "+err.Error()) return @@ -391,7 +392,7 @@ func (this *Node) syncConfig(taskVersion int64) error { return err } - err, serverErrors := nodeConfig.Init(nil) + err, serverErrors := nodeConfig.Init(context.Background()) if err != nil { return err } @@ -1034,7 +1035,7 @@ func (this *Node) reloadServer() { remotelogs.Debug("NODE", "reload "+types.String(countUpdatingServers)+" servers") } - err, serverErrors := newNodeConfig.Init(nil) + err, serverErrors := newNodeConfig.Init(context.Background()) if err != nil { remotelogs.Error("NODE", "apply server config error: "+err.Error()) return diff --git a/internal/nodes/node_panic_arm64.go b/internal/nodes/node_panic_arm64.go index c38fec8..c041987 100644 --- a/internal/nodes/node_panic_arm64.go +++ b/internal/nodes/node_panic_arm64.go @@ -1,10 +1,9 @@ // Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. //go:build arm64 -// +build arm64 package nodes // 处理异常 func (this *Node) handlePanic() { - return + } diff --git a/internal/utils/expires/list_test.go b/internal/utils/expires/list_test.go index 1ba1eac..bc39ac4 100644 --- a/internal/utils/expires/list_test.go +++ b/internal/utils/expires/list_test.go @@ -122,7 +122,7 @@ func TestList_ManyItems(t *testing.T) { }) list.GC(time.Now().Unix() + 1) t.Log("gc", count, "items") - t.Log(time.Now().Sub(now)) + t.Log(time.Since(now)) } func TestList_Map_Performance(t *testing.T) { @@ -140,7 +140,7 @@ func TestList_Map_Performance(t *testing.T) { for i := 0; i < 100_000; i++ { delete(m, int64(i)) } - t.Log(time.Now().Sub(now)) + t.Log(time.Since(now)) } { diff --git a/internal/waf/requests/test_request.go b/internal/waf/requests/test_request.go index a9e2810..656df62 100644 --- a/internal/waf/requests/test_request.go +++ b/internal/waf/requests/test_request.go @@ -88,3 +88,7 @@ func (this *TestRequest) DisableAccessLog() { func (this *TestRequest) ProcessResponseHeaders(headers http.Header, status int) { } + +func (this *TestRequest) WAFMaxRequestSize() int64 { + return 1 << 20 +} diff --git a/internal/waf/values/ip_range.go b/internal/waf/values/ip_range.go index ddd4c97..3e71f34 100644 --- a/internal/waf/values/ip_range.go +++ b/internal/waf/values/ip_range.go @@ -34,7 +34,7 @@ func (this *IPRange) Contains(netIP net.IP) bool { } case IPRangeTypeSingeIP: if this.IPFrom != nil { - return bytes.Equal(this.IPFrom, netIP) + return this.IPFrom.Equal(netIP) } case IPRangeTypeRange: return bytes.Compare(this.IPFrom, netIP) <= 0 && bytes.Compare(this.IPTo, netIP) >= 0