spacewander commented on a change in pull request #63:
URL:
https://github.com/apache/apisix-go-plugin-runner/pull/63#discussion_r804383251
##########
File path: internal/plugin/plugin.go
##########
@@ -134,7 +136,9 @@ func reportAction(id uint32, req *inHTTP.Request, resp
*inHTTP.Response) *flatbu
}
func HTTPReqCall(buf []byte, conn net.Conn) (*flatbuffers.Builder, error) {
- req := inHTTP.CreateRequest(buf)
+ ctx, cancel := context.WithTimeout(context.Background(), 56*time.Second)
+ defer cancel()
+ req := inHTTP.CreateRequest(buf).WithContext(ctx)
Review comment:
Better to set the ctx inside `CreateRequest` instead of providing it as
a method.
As we will reuse the Request, such a method will make reusing impossible.
##########
File path: internal/plugin/plugin.go
##########
@@ -134,7 +136,9 @@ func reportAction(id uint32, req *inHTTP.Request, resp
*inHTTP.Response) *flatbu
}
func HTTPReqCall(buf []byte, conn net.Conn) (*flatbuffers.Builder, error) {
- req := inHTTP.CreateRequest(buf)
+ ctx, cancel := context.WithTimeout(context.Background(), 56*time.Second)
Review comment:
Better to add a comment to explain why 56 is chosen.
##########
File path: internal/http/request.go
##########
@@ -18,18 +18,18 @@
package http
import (
+ "context"
"encoding/binary"
+ "github.com/api7/ext-plugin-proto/go/A6"
Review comment:
Let's configure your environment to make sure 3 party imports are sorted
separated.
##########
File path: internal/http/request.go
##########
@@ -52,6 +52,26 @@ type Request struct {
rawArgs url.Values
vars map[string][]byte
+
+ ctx context.Context
+}
+
+func (r *Request) Context() context.Context {
+ if r.ctx != nil {
+ return r.ctx
Review comment:
Don't forget to reset the ctx before reusing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]