Skip to content

Commit fa27f96

Browse files
extproc: call defer cancel
Signed-off-by: Hrushikesh Patil <[email protected]>
1 parent ef58e8f commit fa27f96

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

internal/extproc/server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (s *Server) Process(stream extprocv3.ExternalProcessor_ProcessServer) error
150150
// an earlier filter has already processed the request headers/bodies and decided to terminate
151151
// the request by sending an immediate response. In this case, we will use the passThroughProcessor
152152
// to pass the request through without any processing as there would be nothing to process from AI Gateway's perspective.
153-
var p Processor = passThroughProcessor{}
153+
var p Processor
154154
var isUpstreamFilter bool
155155
var internalReqID string
156156
var originalReqID string
@@ -233,7 +233,10 @@ func (s *Server) Process(stream extprocv3.ExternalProcessor_ProcessServer) error
233233
logger = s.logger.With("request_id", originalReqID, "is_upstream_filter", isUpstreamFilter)
234234
}
235235

236-
// At this point, p is guaranteed to be a valid processor either from the concrete processor or the passThroughProcessor.
236+
// At this point, ensure p has a valid processor either from the concrete processor or the passThroughProcessor.
237+
if p == nil {
238+
p = passThroughProcessor{}
239+
}
237240
resp, err := s.processMsg(ctx, logger, p, req, internalReqID, isUpstreamFilter)
238241
if err != nil {
239242
s.logger.Error("error processing request message", slog.String("error", err.Error()))

tests/extproc/mcp/mcp_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ func testNotificationCancelled(t *testing.T, m *mcpEnv) {
675675
s := m.newSession(t)
676676

677677
ctx, cancel := context.WithCancel(t.Context()) //nolint: govet
678+
defer cancel()
678679
doneCh := make(chan any)
679680
go func() {
680681
_, _ = s.session.CallTool(ctx, &mcp.CallToolParams{

0 commit comments

Comments
 (0)