You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ba...@apache.org on 2026/08/24 04:53:13 UTC

(dubbo-go-pixiu) branch develop updated: fix(accesslog): avoid max latency after decode short-circuit (#116) (#1020)

This is an automated email from the ASF dual-hosted git repository.

baerwang pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu.git


The following commit(s) were added to refs/heads/develop by this push:
     new a84c5bb8b fix(accesslog): avoid max latency after decode short-circuit (#116) (#1020)
a84c5bb8b is described below

commit a84c5bb8bc738a3b16ebd87818f0b62433c6f309
Author: dubbo-go-bot <du...@outlook.com>
AuthorDate: Mon Aug 24 12:53:07 2026 +0800

    fix(accesslog): avoid max latency after decode short-circuit (#116) (#1020)
    
    * fix(accesslog): avoid max latency after decode short-circuit
    
    * test(accesslog): bound wait for log entry
    
    Co-authored-by: EmptyCity-111 <30...@qq.com>
---
 pkg/filter/accesslog/access_log.go      |  5 ++--
 pkg/filter/accesslog/access_log_test.go | 48 +++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/pkg/filter/accesslog/access_log.go b/pkg/filter/accesslog/access_log.go
index 2aa26e0c6..ffac46129 100644
--- a/pkg/filter/accesslog/access_log.go
+++ b/pkg/filter/accesslog/access_log.go
@@ -79,8 +79,9 @@ func (factory *FilterFactory) PrepareFilterChain(ctx *http.HttpContext, chain fi
 	// Make a shallow copy of the factory config to avoid sharing the factory's pointer.
 	cpConf := *factory.conf
 	f := &Filter{
-		conf: &cpConf,
-		alw:  factory.alw,
+		conf:  &cpConf,
+		alw:   factory.alw,
+		start: time.Now(),
 	}
 	chain.AppendDecodeFilters(f)
 	chain.AppendEncodeFilters(f)
diff --git a/pkg/filter/accesslog/access_log_test.go b/pkg/filter/accesslog/access_log_test.go
index e8c4d5c9d..9cde73ad2 100644
--- a/pkg/filter/accesslog/access_log_test.go
+++ b/pkg/filter/accesslog/access_log_test.go
@@ -21,6 +21,8 @@ import (
 	"bytes"
 	"net/http"
 	"os"
+	"regexp"
+	"strconv"
 	"testing"
 	"time"
 )
@@ -32,10 +34,20 @@ import (
 import (
 	"github.com/apache/dubbo-go-pixiu/pkg/client"
 	"github.com/apache/dubbo-go-pixiu/pkg/common/constant"
+	filterapi "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+	contexthttp "github.com/apache/dubbo-go-pixiu/pkg/context/http"
 	"github.com/apache/dubbo-go-pixiu/pkg/context/mock"
 	"github.com/apache/dubbo-go-pixiu/pkg/logger"
 )
 
+var accessLogCostPattern = regexp.MustCompile(`cost time \[ ([0-9]+) \]`)
+
+type stoppingDecodeFilter struct{}
+
+func (stoppingDecodeFilter) Decode(*contexthttp.HttpContext) filterapi.FilterStatus {
+	return filterapi.Stop
+}
+
 func TestAccessLog_Write_to_file(t *testing.T) {
 	msg := "this is test msg"
 
@@ -77,3 +89,39 @@ func TestApply(t *testing.T) {
 	}
 	assert.FileExists(t, filePath, nil)
 }
+
+func TestEncodeWithoutDecodeReportsBoundedLatency(t *testing.T) {
+	logData := make(chan AccessLogData, 1)
+	factory := &FilterFactory{
+		conf: &AccessLogConfig{},
+		alw:  &AccessLogWriter{AccessLogDataChan: logData},
+	}
+	chain := filterapi.NewDefaultFilterChain()
+	chain.AppendDecodeFilters(stoppingDecodeFilter{})
+
+	request, err := http.NewRequest(http.MethodGet, "http://www.dubbogopixiu.com/blocked", nil)
+	assert.NoError(t, err)
+	ctx := mock.GetMockHTTPContext(request)
+	ctx.TargetResp = client.NewUnaryResponse([]byte("blocked"))
+
+	assert.NoError(t, factory.PrepareFilterChain(ctx, chain))
+	chain.OnDecode(ctx)
+	chain.OnEncode(ctx)
+
+	var entry AccessLogData
+	timer := time.NewTimer(time.Second)
+	defer timer.Stop()
+	select {
+	case entry = <-logData:
+	case <-timer.C:
+		t.Fatal("timed out waiting for access-log entry")
+	}
+
+	matches := accessLogCostPattern.FindStringSubmatch(entry.AccessLogMsg)
+	if assert.Len(t, matches, 2) {
+		latency, parseErr := strconv.ParseInt(matches[1], 10, 64)
+		if assert.NoError(t, parseErr) {
+			assert.Less(t, time.Duration(latency), time.Minute)
+		}
+	}
+}