easegress icon indicating copy to clipboard operation
easegress copied to clipboard

It will hapen endless loop when a http request through a mirror pool of pipeline

Open thewangzl opened this issue 2 years ago • 6 comments

Describe the bug when I config the pipeline with mainPool and a mirrorPool,and request with http header to through the mirrorPool(like example http-pipeline-example.yaml in source, set header X-Filter=mirror ), it will response nothing

To Reproduce Steps to reproduce the behavior:

  1. update http-pipeline-example.yaml in example/config,keep mainPool and mirrorPool,just remain http-pipeline-example.yaml and http-server-example.yaml
  2. start cluster and create objects
  3. send request with header X-Filter=mirror
  4. cannot get any response

Expected behavior response correct data

Version all version

Configuration

  • HTTP server configuration
kind: HTTPServer
name: http-server-example
port: 10080
https: false
http3: false
keepAlive: true
keepAliveTimeout: 75s
maxConnection: 10240
cacheSize: 0
rules:
  - paths:
    - pathPrefix: /pipeline
      backend: http-pipeline-example
  • Pipeline Configuration
name: http-pipeline-example
kind: HTTPPipeline

flow:
  - filter: proxy
    jumpIf: { fallback: END }
  - filter: responseAdaptor

filters:
  - name: proxy
    kind: Proxy
    failureCodes: [500, 501]
    fallback:
      forCodes: true
      forCircuitBreaker: false
      mockCode: 200
      mockHeader: {X-Fallback: yes}
      mockBody: '{"message": "Backend failed, try it later."}'
    mirrorPool:
      servers:
      - url: http://127.0.0.1:9092
      loadBalance:
        policy: roundRobin
        headerHashKey: ""
      filter:
        headers:
          X-Filter:
            exact: mirror
    mainPool:
      servers:
      - url: http://127.0.0.1:9091
        tags: ["blue", "v2"]
      loadBalance:
        policy: roundRobin
        headerHashKey: X-User-Id
    compression:
      minLength: 1024
  - name: responseAdaptor
    kind: ResponseAdaptor
    header:
      del: []
      set:
        Server: Easegress v1.0.0
      add:
        X-Proxy-Name: http-proxy-exmaple

thewangzl avatar Jun 20 '22 01:06 thewangzl

I review the code, in proxy.go,primaryReader and body of HttpRequest reference each other. when method body.Close() is called in httpContext.Finish(),primaryReader.Close() is called, and then body.Close() ...

thewangzl avatar Jun 20 '22 01:06 thewangzl

Thanks for raising this, we will look into the issue, and also welcome you to open a PR to fix it.

localvar avatar Jun 20 '22 01:06 localvar

Hi, thanks for your question. mirrorPool just send the requests to corresponding backend, the response from mirrorPool is ignored (it is just a mirror, the response comes from mainPool or one of candidatePools). So do you mean mirrorPool backend does not get the request or just mirrorPool response not return?

If you want to use filter to send requests to different backends, please use candidatePools...

suchen-sci avatar Jun 20 '22 02:06 suchen-sci

@suchen-sci I see mirrorPool will not writeResponse. but when body.close,It will has a endless loop between body.Close() and primaryReader.Close(),because both of them try to call the other one actually.

thewangzl avatar Jun 20 '22 06:06 thewangzl

Yeah you are right... @thewangzl fix this problem is a little bit complex... let us discuss it, the problem is in SetBody part. For now, please use candidatePools, they works well.

suchen-sci avatar Jun 20 '22 07:06 suchen-sci

I see.

thewangzl avatar Jun 20 '22 08:06 thewangzl

It seems this problem has been solved during update of easegress 2.0. Please reopen it if you have any problem about it.

suchen-sci avatar Jan 10 '24 07:01 suchen-sci