Skip to content
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

fix reuse fasthttp response #403

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,8 @@ func (a *agentMessageHandler) httpCall(request motan.Request, ck string, httpClu
}
httpRequest := fasthttp.AcquireRequest()
httpResponse := fasthttp.AcquireResponse()
// do not release http response
defer fasthttp.ReleaseRequest(httpRequest)
defer fasthttp.ReleaseResponse(httpResponse)
httpRequest.Header.Del("Host")
httpRequest.SetHost(originalService)
httpRequest.URI().SetPath(request.GetMethod())
Expand Down
3 changes: 1 addition & 2 deletions ha/backupRequestHA.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ func (br *BackupRequestHA) Call(request motan.Request, loadBalance motan.LoadBal
break
}
// log & clone backup request
pr := request
pr := request.Clone().(motan.Request)
if i > 0 {
vlog.Infof("[backup request ha] delay %d request id: %d, service: %s, method: %s", delay, request.GetRequestID(), request.GetServiceName(), request.GetMethod())
pr = request.Clone().(motan.Request)
}
lastErrorCh = make(chan motan.Response, 1)
go func(postRequest motan.Request, endpoint motan.EndPoint, errorCh chan motan.Response) {
Expand Down
1 change: 1 addition & 0 deletions http/httpProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ func MotanRequestToFasthttpRequest(motanRequest core.Request, fasthttpRequest *f
}

// FasthttpResponseToMotanResponse convert a http response to a motan response
// Notice:: Do not release HttpResponse early using this method
// For http mesh server side, the httpServer response to the server agent but client need a motan response
// Contrast to request convert, we put all headers to meta, an body maybe just use it with type []byte
func FasthttpResponseToMotanResponse(motanResponse core.Response, fasthttpResponse *fasthttp.Response) {
Expand Down
6 changes: 6 additions & 0 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ func (d *defaultLogger) AccessLog(logObject *AccessLogEntity) {
}

func (d *defaultLogger) doAccessLog(logObject *AccessLogEntity) {
defer func() {
if err := recover(); err != nil {
log.Printf("doAccessLog failed. err:%v, logObject: %+v", err, logObject)
debug.PrintStack()
}
}()
if d.accessStructured {
d.accessLogger.Info("",
zap.String("filterName", logObject.FilterName),
Expand Down
2 changes: 1 addition & 1 deletion meshClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func (c *MeshClient) BaseCall(request core.Request, reply interface{}) core.Resp
}
httpRequest := fasthttp.AcquireRequest()
httpResponse := fasthttp.AcquireResponse()
// do not release http response
defer fasthttp.ReleaseRequest(httpRequest)
defer fasthttp.ReleaseResponse(httpResponse)
httpRequest.Header.Del("Host")
httpRequest.SetHost(request.GetServiceName())
httpRequest.URI().SetPath(request.GetMethod())
Expand Down
2 changes: 1 addition & 1 deletion provider/httpProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (h *HTTPProvider) DoTransparentProxy(request motan.Request, t int64, ip str
fillHttpException(resp, http.StatusNotFound, t, err.Error())
return resp
}
// sets rewrite
// set rewrite
httpReq.URI().SetScheme(h.proxySchema)
httpReq.URI().SetPath(rewritePath)
request.GetAttachments().Range(func(k, v string) bool {
Expand Down
Loading