Skip to content

Commit

Permalink
Merge pull request #403 from cocowh/fix_syncpoll_reuse
Browse files Browse the repository at this point in the history
fix reuse fasthttp response
  • Loading branch information
rayzhang0603 authored Aug 30, 2024
2 parents 9a0f42f + 7877647 commit b63a532
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
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

0 comments on commit b63a532

Please sign in to comment.