fix: handle nil edge cases in coprocess BuildObject and ProtoSessionState#7998
fix: handle nil edge cases in coprocess BuildObject and ProtoSessionState#7998probelabs[bot] wants to merge 4 commits into
Conversation
🚨 Jira Linter FailedCommit: The Jira linter failed to validate your PR. Please check the error details below: 🔍 Click to view error detailsNext Steps
This comment will be automatically deleted once the linter passes. |
|
This PR introduces several nil-safety checks to the gRPC coprocess functionality, hardening the system against potential panics from unexpected inputs. It also adds new tests, including benchmarks and a memory leak test, to ensure the stability and performance of these components. Files Changed Analysis
Architecture & Impact AssessmentWhat this PR accomplishes: Key technical changes introduced:
Affected system components: sequenceDiagram
participant Gateway
participant gRPC Plugin
Gateway->>Gateway: Receives API Request
Gateway->>Gateway: Middleware Chain Execution
Note over Gateway: CoProcess Middleware triggered
Gateway->>Gateway: BuildObject(req, res, spec)
Note right of Gateway: PR adds nil checks for req, req.URL, req.Header, res.Body
Gateway->>Gateway: ProtoSessionState(session)
Note right of Gateway: PR adds nil check for session
Gateway->>gRPC Plugin: Dispatch(Coprocess.Object)
gRPC Plugin->>Gateway: Return Modified Object
Gateway->>Gateway: TykSessionState(protoSession)
Note right of Gateway: PR adds nil check for protoSession
Gateway->>Gateway: Continue Middleware Chain
Scope Discovery & Context ExpansionThe changes are localized to the The addition of memory-related tests in Metadata
Powered by Visor from Probelabs Last updated: 2026-04-13T20:46:01.438Z | Triggered by: pr_opened | Commit: 5041b5a 💡 TIP: You can chat with Visor using |
✅ Security Check PassedNo security issues found – changes LGTM. Performance Issues (1)
✅ Security Check PassedNo security issues found – changes LGTM. \n\n \n\nPerformance Issues (1)
Powered by Visor from Probelabs Last updated: 2026-04-13T20:45:37.405Z | Triggered by: pr_opened | Commit: 5041b5a 💡 TIP: You can chat with Visor using |
|
API Changes no api changes detected |
|




Problem / Task
The user wants to ensure edge cases (like nil objects) are handled carefully and covered with a lot of tests in
ProtoSessionStateandBuildObject.Changes
sessioninProtoSessionStateandTykSessionState.reqinBuildObject.req.URLinBuildObject.req.HeaderinBuildObjectbefore assigning to it.res.BodyinBuildObjectbefore reading it.gateway/coprocess_test.goandgateway/coprocess_helpers_test.go.Testing
go test -v -run TestBuildObject_NilRequest ./gateway/go test -v -run TestBuildObject_EmptyHeaders ./gateway/go test -v -run TestBuildObject_NilResponseBody ./gateway/go test -v -run TestProtoSessionState_Nil ./gateway/go test -v -run TestTykSessionState_Nil ./gateway/All tests pass successfully.