Caddy: lookup_srv wrong behaviour for "no such host" errors

Created on 29 Sep 2020  路  3Comments  路  Source: caddyserver/caddy

The expected error for DNS lookup errors in lookup_srv should be the same as dial.

How to reproduce

{
  "admin": {
    "disabled": true
  },
  "apps": {
    "http": {
      "servers": {
        "srv0": {
          "errors": {
            "routes": [
              {
                "handle": [                  
                  {
                    "handler": "rewrite",
                    "uri": "/502.html"
                  },
                  {
                    "handler": "file_server",
                    "hide": [
                      "caddy.json"
                    ]
                  }
                ],
                "match": [
                  {
                    "expression": "{http.error.status_code} == 502"
                  }
                ],
                "terminal": true
              }
            ]
          },
          "listen": [
            ":443"
          ],          
          "routes": [
            {
              "handle": [                
                {
                  "handler": "reverse_proxy",
                  "upstreams": [
                    {
                      "lookup_srv": "wguoihebfoindfoibnwpoefjoienbfgiberish.com"
                    }
                  ]
                }
              ],
              "match": [
                {
                  "host": [
                    "localhost"
                  ]
                }
              ],
              "terminal": true
            }
          ]
        }
      }
    }
  }  
}

This config will fail to render the 502 error page because Caddy is returning a 500 due to the no such host error from the DNS lookup failure.

However, if you change "lookup_srv": "wguoihebfoindfoibnwpoefjoienbfgiberish.com" to "dial": "wguoihebfoindfoibnwpoefjoienbfgiberish.com:80" Caddy will render the 502 error page as expected.

Both failures should result in a 502

bug good first issue help wanted

Most helpful comment

Ok, looks like i fixed it locally. I'll check if everything else if fine and then make a PR.

All 3 comments

Ok, looks like i fixed it locally. I'll check if everything else if fine and then make a PR.

3771

It renders 502 error page both for lookup_srv and dial config entry, however i build from #3756 to actually check lookup_srv since it's not working on master.

I think that's a simple and effective fix! Thanks for that @aleert

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dafanasiev picture dafanasiev  路  3Comments

mholt picture mholt  路  3Comments

PhilmacFLy picture PhilmacFLy  路  3Comments

muhammadmuzzammil1998 picture muhammadmuzzammil1998  路  3Comments

aeroxy picture aeroxy  路  3Comments