Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: resolve context propagation lint findings
  • Loading branch information
XnLemon committed Jul 30, 2026
commit 2c5d25e44b34859f8424c8e5ca8efc31afea9908
6 changes: 4 additions & 2 deletions metadata/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
}
)

type metadataContextKey struct{}

func TestConvertMetadataInfoV2PreservesTag(t *testing.T) {
got := convertMetadataInfoV2(&tripleapi.MetadataInfoV2{
App: "dubbo-app",
Expand Down Expand Up @@ -200,7 +202,7 @@
}).Once()
mockInvoker.On("Destroy").Once()

ctx := context.WithValue(context.Background(), struct{}{}, "request-value")
ctx := context.WithValue(context.Background(), metadataContextKey{}, "request-value")
metadata, err := GetMetadataFromRpcWithContext(ctx, "111", ins)
require.NoError(t, err)
assert.Equal(t, metadataInfo, metadata)
Expand All @@ -212,7 +214,7 @@
mockInvoker.url = common.NewURLWithOptions(common.WithProtocol(constant.TriProtocol))
mockInvoker.On("Invoke").Return(&result.RPCResult{Attrs: map[string]any{}}).Once()

ctx := context.WithValue(context.Background(), struct{}{}, "request-value")
ctx := context.WithValue(context.Background(), metadataContextKey{}, "request-value")
metadata, err := (&triMetadataServiceV2{invoker: mockInvoker}).getMetadataInfo(ctx, "111")
require.NoError(t, err)
require.NotNil(t, metadata)
Expand Down Expand Up @@ -410,7 +412,7 @@

type mockInvoker struct {
mock.Mock
invokedContext context.Context

Check warning on line 415 in metadata/client_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'context.Context' field and pass context as a parameter to methods that need it.

See more on https://sonarcloud.io/project/issues?id=apache_dubbo-go&issues=AZ-yUvuzoGPlgbDGtsVG&open=AZ-yUvuzoGPlgbDGtsVG&pullRequest=3579
url *common.URL
}

Expand Down
4 changes: 2 additions & 2 deletions protocol/rest/server/rest_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func GetRouteFunc(invoker base.Invoker, methodConfig *rest_config.RestMethodConf
rawRequest := req.RawRequest()
Comment thread
XnLemon marked this conversation as resolved.
Resolved
if rawRequest == nil {
logger.Errorf("[Rest][Server] request adapter returned a nil raw request")
if err := resp.WriteError(http.StatusInternalServerError, errors.New("raw HTTP request is nil")); err != nil {
logger.Errorf("[Rest][Server] write error failed, err=%v", err)
if writeErr := resp.WriteError(http.StatusInternalServerError, errors.New("raw HTTP request is nil")); writeErr != nil {
logger.Errorf("[Rest][Server] write error failed, err=%v", writeErr)
}
return
}
Expand Down
Loading