Strange bug mitmdump ssl

I have a strange bug with mitmdump both on release and 4.0.0.dev169
I’m running it with mitmdump -p 8888

I can reproduce the bug on this url
https://search.tez-tour.com/tariffsearch/refs?callback=jsonp1522770924501&_=1522770924725&locale=ru&rfCityId=345

also reproduces on another url on another host

the bug is that sometimes mitmdump returns 502 Bad Gateway

here is request (curl bash copy) but bug is in browser:

curl 'https://search.tez-tour.com/tariffsearch/refs?callback=jsonp1522770924501&_=1522770924725&locale=ru&rfCityId=345' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Cookie: aid=BF72DA5E8AA6C7EC07339A1D83824B19A44D589E20180403185058.m08; agency_auth_ga=true' -H 'Connection: keep-alive' --compressed

HAR

{
  "log": {
    "version": "1.2",
    "creator": {
      "name": "WebInspector",
      "version": "537.36"
    },
    "pages": [
      {
        "startedDateTime": "2018-04-03T16:24:47.547Z",
        "id": "page_288",
        "title": "https://search.tez-tour.com/tariffsearch/refs?callback=jsonp1522770924501&_=1522770924725&locale=ru&rfCityId=345",
        "pageTimings": {
          "onContentLoad": 46.846000012010336,
          "onLoad": 45.799999963492155
        }
      }
    ],
    "entries": [
      {
        "startedDateTime": "2018-04-03T16:24:47.582Z",
        "time": 32.3449998870492,
        "request": {
          "method": "GET",
          "url": "https://search.tez-tour.com/tariffsearch/refs?callback=jsonp1522770924501&_=1522770924725&locale=ru&rfCityId=345",
          "httpVersion": "HTTP/1.1",
          "headers": [
            {
              "name": "Accept-Encoding",
              "value": "gzip, deflate, br"
            },
            {
              "name": "Host",
              "value": "search.tez-tour.com"
            },
            {
              "name": "Accept-Language",
              "value": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7"
            },
            {
              "name": "Upgrade-Insecure-Requests",
              "value": "1"
            },
            {
              "name": "User-Agent",
              "value": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
            },
            {
              "name": "Accept",
              "value": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
            },
            {
              "name": "Cache-Control",
              "value": "max-age=0"
            },
            {
              "name": "Cookie",
              "value": "aid=BF72DA5E8AA6C7EC07339A1D83824B19A44D589E20180403185058.m08; agency_auth_ga=true"
            },
            {
              "name": "Connection",
              "value": "keep-alive"
            }
          ],
          "queryString": [
            {
              "name": "callback",
              "value": "jsonp1522770924501"
            },
            {
              "name": "_",
              "value": "1522770924725"
            },
            {
              "name": "locale",
              "value": "ru"
            },
            {
              "name": "rfCityId",
              "value": "345"
            }
          ],
          "cookies": [
            {
              "name": "aid",
              "value": "BF72DA5E8AA6C7EC07339A1D83824B19A44D589E20180403185058.m08",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "agency_auth_ga",
              "value": "true",
              "expires": null,
              "httpOnly": false,
              "secure": false
            }
          ],
          "headersSize": 609,
          "bodySize": 0
        },
        "response": {
          "status": 502,
          "statusText": "Bad Gateway",
          "httpVersion": "HTTP/1.1",
          "headers": [
            {
              "name": "Server",
              "value": "mitmproxy 4.0.0"
            },
            {
              "name": "Connection",
              "value": "close"
            },
            {
              "name": "Content-Length",
              "value": "256"
            },
            {
              "name": "Content-Type",
              "value": "text/html"
            }
          ],
          "cookies": [],
          "content": {
            "size": 256,
            "mimeType": "text/html",
            "compression": 0
          },
          "redirectURL": "",
          "headersSize": 118,
          "bodySize": 256,
          "_transferSize": 374
        },
        "cache": {},
        "timings": {
          "blocked": 0.88599992543459,
          "dns": -1,
          "ssl": -1,
          "connect": -1,
          "send": 0.1650000922381898,
          "wait": 31.293999869376417,
          "receive": 0,
          "_blocked_queueing": -1
        },
        "serverIPAddress": "95.163.98.155",
        "connection": "14293",
        "pageref": "page_288"
      }
    ]
  }
}

and info from mitmdump -vv

95.84.194.194:55043: GET https://search.tez-tour.com/tariffsearch/refs?callback=jsonp1522770924501&_=1522770924725&locale=ru&rfCityId=345
    Host: search.tez-tour.com
    Connection: keep-alive
    Cache-Control: max-age=0
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    Accept-Encoding: gzip, deflate, br
    Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
    Cookie: aid=BF72DA5E8AA6C7EC07339A1D83824B19A44D589E20180403185058.m08; agency_auth_ga=true
 << 200 OK 2.11k
    Server: nginx
    Date: Tue, 03 Apr 2018 16:18:41 GMT
    Content-Type: application/json;charset=utf-8
    Transfer-Encoding: chunked
    Connection: keep-alive
    Vary: Accept-Encoding
    Access-Control-Allow-Origin: *
    X-Cache-Status: MISS
    X-SRV: 185
    Content-Encoding: gzip
95.84.194.194:55043: request
  -> Request(GET /tariffsearch/refs?callback=jsonp1522770924501&_=1522770924725&locale=ru&rfCityId=345)
95.84.194.194:55043: response
  -> Response(200 OK, application/json;charset=utf-8, 2.11k)
95.84.194.194:55043: GET https://search.tez-tour.com/tariffsearch/refs?callback=jsonp1522770924501&_=1522770924725&locale=ru&rfCityId=345
    Host: search.tez-tour.com
    Connection: keep-alive
    Cache-Control: max-age=0
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    Accept-Encoding: gzip, deflate, br
    Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
    Cookie: aid=BF72DA5E8AA6C7EC07339A1D83824B19A44D589E20180403185058.m08; agency_auth_ga=true
 << 200 OK 2.11k
    Server: nginx
    Date: Tue, 03 Apr 2018 16:18:41 GMT
    Content-Type: application/json;charset=utf-8
    Transfer-Encoding: chunked
    Connection: keep-alive
    Vary: Accept-Encoding
    Access-Control-Allow-Origin: *
    X-Cache-Status: MISS
    X-SRV: 185
    Content-Encoding: gzip
95.84.194.194:55043: request
  -> Request(GET /tariffsearch/refs?callback=jsonp1522770924501&_=1522770924725&locale=ru&rfCityId=345)
95.84.194.194:55043: GET https://search.tez-tour.com/tariffsearch/refs?callback=jsonp1522770924501&_=1522770924725&locale=ru&rfCityId=345
    Host: search.tez-tour.com
    Connection: keep-alive
    Cache-Control: max-age=0
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    Accept-Encoding: gzip, deflate, br
    Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
    Cookie: aid=BF72DA5E8AA6C7EC07339A1D83824B19A44D589E20180403185058.m08; agency_auth_ga=true
 << Server disconnected
95.84.194.194:55043: serverdisconnect
  -> ('search.tez-tour.com', 443)
95.84.194.194:55043: clientdisconnect
95.84.194.194:55039: clientdisconnect
95.84.194.194:55061: clientconnect
95.84.194.194:55061: Set new server address: search.tez-tour.com:443
95.84.194.194:55061: serverconnect
  -> ('search.tez-tour.com', 443)
95.84.194.194:55061: Establish TLS with server
95.84.194.194:55061: ALPN selected by server: -
95.84.194.194:55061: Establish TLS with client
95.84.194.194:55061: ALPN for client: b'http/1.1'
95.84.194.194:55061: request
  -> Request(GET /tariffsearch/refs?callback=jsonp1522770924501&_=1522770924725&locale=ru&rfCityId=345)
95.84.194.194:55061: response
  -> Response(200 OK, application/json;charset=utf-8, 2.11k)
95.84.194.194:55061: GET https://search.tez-tour.com/tariffsearch/refs?callback=jsonp1522770924501&_=1522770924725&locale=ru&rfCityId=345
    Host: search.tez-tour.com
    Connection: keep-alive
    Cache-Control: max-age=0
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    Accept-Encoding: gzip, deflate, br
    Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
    Cookie: aid=BF72DA5E8AA6C7EC07339A1D83824B19A44D589E20180403185058.m08; agency_auth_ga=true
 << 200 OK 2.11k
    Server: nginx
    Date: Tue, 03 Apr 2018 16:18:42 GMT
    Content-Type: application/json;charset=utf-8
    Transfer-Encoding: chunked
    Connection: keep-alive
    Vary: Accept-Encoding
    Access-Control-Allow-Origin: *
    X-Cache-Status: MISS
    X-SRV: 185
    Content-Encoding: gzip

Thanks for the report. This probably is the same issue as https://github.com/mitmproxy/mitmproxy/issues/3038. :slight_smile:

seems fixed, thanks!