-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TT-11960]fix panic in Oas when using mode public #6241
base: master
Are you sure you want to change the base?
Conversation
PR Description updated to latest commit (f1acfa8) |
API Changes no api changes detected |
PR Review
Code feedback:
✨ Review tool usage guide:Overview: The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
See the review usage page for a comprehensive guide on using this tool. |
PR Code Suggestions
✨ Improve tool usage guide:Overview:
See the improve usage page for a comprehensive guide on using this tool. |
Quality Gate failedFailed conditions See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
💥 CI tests failed 🙈git-statediff --git a/gateway/api.go b/gateway/api.go
index ae50f95..ae1d25c 100644
--- a/gateway/api.go
+++ b/gateway/api.go
@@ -3478,4 +3478,4 @@ func updateOASServers(spec *APISpec, conf config.Config, apiDef *apidef.APIDefin
newAPIURL := getAPIURL(*apiDef, conf)
oasObj.UpdateServers(newAPIURL, oldAPIURL)
-}
\ No newline at end of file
+} Please look at the run or in the Checks tab. |
@@ -1039,7 +1039,9 @@ func (gw *Gateway) handleGetAPIOAS(apiID string, modePublic bool) (interface{}, | |||
|
|||
obj, code := gw.handleGetAPI(apiID, true) | |||
if apiOAS, ok := obj.(*oas.OAS); ok && modePublic { | |||
apiOAS.RemoveTykExtension() | |||
oasCopy := *apiOAS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use OAS.Clone for a deep copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use OAS.Clone for a deep copy.
@titpetric I have tried to use OAS.Clone but when I use OAS.Clone it still panics. I am not sure why
💥 CI tests failed 🙈git-statediff --git a/gateway/api.go b/gateway/api.go
index 1ea518b..d7e88f5 100644
--- a/gateway/api.go
+++ b/gateway/api.go
@@ -1039,8 +1039,8 @@ func (gw *Gateway) handleGetAPIOAS(apiID string, modePublic bool) (interface{},
obj, code := gw.handleGetAPI(apiID, true)
if apiOAS, ok := obj.(*oas.OAS); ok && modePublic {
- oasCopy,err := apiOAS.Clone()
- if(err!=nil){
+ oasCopy, err := apiOAS.Clone()
+ if err != nil {
return apiError("marshalling failed"), http.StatusInternalServerError
}
oasCopy.RemoveTykExtension()
@@ -3481,4 +3481,4 @@ func updateOASServers(spec *APISpec, conf config.Config, apiDef *apidef.APIDefin
newAPIURL := getAPIURL(*apiDef, conf)
oasObj.UpdateServers(newAPIURL, oldAPIURL)
-}
\ No newline at end of file
+} Please look at the run or in the Checks tab. |
1 similar comment
💥 CI tests failed 🙈git-statediff --git a/gateway/api.go b/gateway/api.go
index 1ea518b..d7e88f5 100644
--- a/gateway/api.go
+++ b/gateway/api.go
@@ -1039,8 +1039,8 @@ func (gw *Gateway) handleGetAPIOAS(apiID string, modePublic bool) (interface{},
obj, code := gw.handleGetAPI(apiID, true)
if apiOAS, ok := obj.(*oas.OAS); ok && modePublic {
- oasCopy,err := apiOAS.Clone()
- if(err!=nil){
+ oasCopy, err := apiOAS.Clone()
+ if err != nil {
return apiError("marshalling failed"), http.StatusInternalServerError
}
oasCopy.RemoveTykExtension()
@@ -3481,4 +3481,4 @@ func updateOASServers(spec *APISpec, conf config.Config, apiDef *apidef.APIDefin
newAPIURL := getAPIURL(*apiDef, conf)
oasObj.UpdateServers(newAPIURL, oldAPIURL)
-}
\ No newline at end of file
+} Please look at the run or in the Checks tab. |
💥 CI tests failed 🙈git-statediff --git a/gateway/api.go b/gateway/api.go
index ae50f95..ae1d25c 100644
--- a/gateway/api.go
+++ b/gateway/api.go
@@ -3478,4 +3478,4 @@ func updateOASServers(spec *APISpec, conf config.Config, apiDef *apidef.APIDefin
newAPIURL := getAPIURL(*apiDef, conf)
oasObj.UpdateServers(newAPIURL, oldAPIURL)
-}
\ No newline at end of file
+} Please look at the run or in the Checks tab. |
Quality Gate passedIssues Measures |
User description
TT-11960
On gateway 5.3.0 I get a panic when I try to fetch a single OAS api when the mode query parameter is set to public.(I am trying to fetch with the endpoint tyk/apis/oas/{apiID}?mode=public) . From the code I can see that a user is allowed to send mode as a query parameter.
This happens Since we return a pointer. When deleting x-tyk-gateway in OAS we get a panic due to a race condition.
Type
bug_fix, enhancement
Description
handleGetAPIOAS
by ensuring that modifications are made on a copy of the object, preventing potential data races.Changes walkthrough
api.go
Fix Race Condition and Code Refactoring in API Handling
gateway/api.go
handleGetAPIOAS
by creating a copy ofapiOAS
before modification.
const
declarations.ioutil.WriteFile
.