-
Notifications
You must be signed in to change notification settings - Fork 19
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
Use of Background Context in triggeraction.go #160
Conversation
Use background context
PR Analysis
PR Feedback
How to use
|
/improve |
@@ -67,7 +67,7 @@ func (resthandler *HTTPHandler) ActionRequest(w http.ResponseWriter, r *http.Req | |||
w.WriteHeader(http.StatusInternalServerError) | |||
bErr, _ := json.Marshal(err) | |||
w.Write(bErr) | |||
logger.L().Ctx(r.Context()).Fatal("recover in ActionRequest", helpers.Interface("error", err)) | |||
logger.L().Ctx(context.Background()).Fatal("recover in ActionRequest", helpers.Interface("error", err)) |
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.
Suggestion: Instead of using context.Background()
, it's better to use the request context r.Context()
. This way, if the request is cancelled for any reason (timeout, client disconnect, etc.), the context will be cancelled as well.
logger.L().Ctx(context.Background()).Fatal("recover in ActionRequest", helpers.Interface("error", err)) | |
logger.L().Ctx(r.Context()).Fatal("recover in ActionRequest", helpers.Interface("error", err)) |
@@ -80,7 +80,7 @@ | |||
if err == nil { | |||
switch r.Method { | |||
case http.MethodPost: | |||
err = resthandler.HandleActionRequest(r.Context(), readBuffer) | |||
err = resthandler.HandleActionRequest(context.Background(), readBuffer) |
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.
Suggestion: Instead of using context.Background()
, it's better to use the request context r.Context()
. This way, if the request is cancelled for any reason (timeout, client disconnect, etc.), the context will be cancelled as well.
err = resthandler.HandleActionRequest(context.Background(), readBuffer) | |
err = resthandler.HandleActionRequest(r.Context(), readBuffer) |
/describe |
PR Type:
Refactoring
PR Description:
This PR modifies the
triggeraction.go
file to use a background context instead of the request context. This change is made in theActionRequest
andHandleActionRequest
functions.PR Main Files Walkthrough:
restapihandler/triggeraction.go
: Replaced the request context with a background context in theActionRequest
andHandleActionRequest
functions.