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

(CCIP) "Error: processing response error" after Error 504 with html body #3148

Closed
0xc0de4c0ffee opened this issue Jul 6, 2022 · 1 comment
Assignees
Labels
investigate Under investigation and may be a bug.

Comments

@0xc0de4c0ffee
Copy link

Ethers Version

5.6.9

Search Terms

ccip, ipns, ipfs

Describe the Problem

Ethers.js isn't fetching next CCIP gateway urls in array after first one throws error 504 with html body.

For better strategy as fallback gateways, it should always retry next URL from list until there's a valid data with status 200 regardless of any previous error status codes.

const result = await fetchJson({ url: href, errorPassThrough: true }, json, (value, response) => {
value.status = response.statusCode;
return value;
});
if (result.data) { return result.data; }
const errorMessage = (result.message || "unknown error");
// 4xx indicates the result is not present; stop
if (result.status >= 400 && result.status < 500) {
return logger.throwError(`response not found during CCIP fetch: ${ errorMessage }`, Logger.errors.SERVER_ERROR, { url, errorMessage });
}
// 5xx indicates server issue; try the next url
errorMessages.push(errorMessage);
}
return logger.throwError(`error encountered during CCIP fetch: ${ errorMessages.map((m) => JSON.stringify(m)).join(", ") }`, Logger.errors.SERVER_ERROR, {
urls, errorMessages
});
}

Code Snippet

// Test CCIP resolver is deployed on goerli 
// 0x0343bB9f32A9b272d4013Ae1Ac5893101CDF7963

let infura = new ethers.providers.InfuraProvider("goerli");

async function test5xxError(){
    let resolver = await infura.getResolver("goerli.namesys.eth");
    resolver.getAddress().then(console.log); // works ok
    

    let resolver2 = await infura.getResolver("error5xx.eth");
    resolver2.getAddress().then(console.log); 
    // expected to switch to second url gateway after 503 error in first url
}

test5xxError();

Contract ABI

No response

Errors

/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/logger/lib/index.js:233
        var error = new Error(message);
                    ^

Error: processing response error (body="<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body>\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>openresty</center>\r\n</body>\r\n</html>\r\n", error={"reason":"invalid JSON","code":"SERVER_ERROR","body":{"0":60,"1":104,"2":116,"3":109,"4":108,"5":62,"6":13,"7":10,"8":60,"9":104,"10":101,"11":97,"12":100,"13":62,"14":60,"15":116,"16":105,"17":116,"18":108,"19":101,"20":62,"21":53,"22":48,"23":52,"24":32,"25":71,"26":97,"27":116,"28":101,"29":119,"30":97,"31":121,"32":32,"33":84,"34":105,"35":109,"36":101,"37":45,"38":111,"39":117,"40":116,"41":60,"42":47,"43":116,"44":105,"45":116,"46":108,"47":101,"48":62,"49":60,"50":47,"51":104,"52":101,"53":97,"54":100,"55":62,"56":13,"57":10,"58":60,"59":98,"60":111,"61":100,"62":121,"63":62,"64":13,"65":10,"66":60,"67":99,"68":101,"69":110,"70":116,"71":101,"72":114,"73":62,"74":60,"75":104,"76":49,"77":62,"78":53,"79":48,"80":52,"81":32,"82":71,"83":97,"84":116,"85":101,"86":119,"87":97,"88":121,"89":32,"90":84,"91":105,"92":109,"93":101,"94":45,"95":111,"96":117,"97":116,"98":60,"99":47,"100":104,"101":49,"102":62,"103":60,"104":47,"105":99,"106":101,"107":110,"108":116,"109":101,"110":114,"111":62,"112":13,"113":10,"114":60,"115":104,"116":114,"117":62,"118":60,"119":99,"120":101,"121":110,"122":116,"123":101,"124":114,"125":62,"126":111,"127":112,"128":101,"129":110,"130":114,"131":101,"132":115,"133":116,"134":121,"135":60,"136":47,"137":99,"138":101,"139":110,"140":116,"141":101,"142":114,"143":62,"144":13,"145":10,"146":60,"147":47,"148":98,"149":111,"150":100,"151":121,"152":62,"153":13,"154":10,"155":60,"156":47,"157":104,"158":116,"159":109,"160":108,"161":62,"162":13,"163":10},"error":{}}, requestBody=null, requestMethod="GET", url="https://ipfs.io/ipns/k51qzi5uqu5dkw20dxdezmzvjrlzx5yz866p3haihbvn1u7vjgltqsrif2pmj1/.well-known/ens/error5xx/addr.json?0xc0de4c0ffeee", code=SERVER_ERROR, version=web/5.6.1)
    at Logger.makeError (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/logger/lib/index.js:233:21)
    at Logger.throwError (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/logger/lib/index.js:242:20)
    at /Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:305:32
    at step (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:33:23)
    at Object.next (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:14:53)
    at fulfilled (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  reason: 'processing response error',
  code: 'SERVER_ERROR',
  body: '<html>\r\n' +
    '<head><title>504 Gateway Time-out</title></head>\r\n' +
    '<body>\r\n' +
    '<center><h1>504 Gateway Time-out</h1></center>\r\n' +
    '<hr><center>openresty</center>\r\n' +
    '</body>\r\n' +
    '</html>\r\n',
  error: Error: invalid JSON (body=Uint8Array(0x3c68746d6c3e0d0a3c686561643e3c7469746c653e35303420476174657761792054696d652d6f75743c2f7469746c653e3c2f686561643e0d0a3c626f64793e0d0a3c63656e7465723e3c68313e35303420476174657761792054696d652d6f75743c2f68313e3c2f63656e7465723e0d0a3c68723e3c63656e7465723e6f70656e72657374793c2f63656e7465723e0d0a3c2f626f64793e0d0a3c2f68746d6c3e0d0a), error={}, code=SERVER_ERROR, version=web/5.6.1)
      at Logger.makeError (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/logger/lib/index.js:233:21)
      at Logger.throwError (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/logger/lib/index.js:242:20)
      at processJsonFunc (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:341:24)
      at /Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:280:46
      at step (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:33:23)
      at Object.next (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:14:53)
      at fulfilled (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:5:58)
      at processTicksAndRejections (node:internal/process/task_queues:96:5) {
    reason: 'invalid JSON',
    code: 'SERVER_ERROR',
    body: Uint8Array(164) [
       60, 104, 116, 109, 108,  62,  13,  10,  60, 104, 101,  97,
      100,  62,  60, 116, 105, 116, 108, 101,  62,  53,  48,  52,
       32,  71,  97, 116, 101, 119,  97, 121,  32,  84, 105, 109,
      101,  45, 111, 117, 116,  60,  47, 116, 105, 116, 108, 101,
       62,  60,  47, 104, 101,  97, 100,  62,  13,  10,  60,  98,
      111, 100, 121,  62,  13,  10,  60,  99, 101, 110, 116, 101,
      114,  62,  60, 104,  49,  62,  53,  48,  52,  32,  71,  97,
      116, 101, 119,  97, 121,  32,  84, 105, 109, 101,  45, 111,
      117, 116,  60,  47,
      ... 64 more items
    ],
    error: SyntaxError: Unexpected token < in JSON at position 0
        at JSON.parse (<anonymous>)
        at processJsonFunc (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:338:31)
        at /Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:280:46
        at step (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:33:23)
        at Object.next (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:14:53)
        at fulfilled (/Users/0xc0de4c0ffee/Documents/Namesys/ethers/node_modules/@ethersproject/web/lib/index.js:5:58)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
  },
  requestBody: null,
  requestMethod: 'GET',
  url: 'https://ipfs.io/ipns/k51qzi5uqu5dkw20dxdezmzvjrlzx5yz866p3haihbvn1u7vjgltqsrif2pmj1/.well-known/ens/error5xx/addr.json?0xc0de4c0ffeee'
}
error Command failed with exit code 1.

Environment

node.js (v12 or newer)

Environment (Other)

No response

@0xc0de4c0ffee 0xc0de4c0ffee added the investigate Under investigation and may be a bug. label Jul 6, 2022
@0xc0de4c0ffee
Copy link
Author

WOW!!

@0xc0de4c0ffee 0xc0de4c0ffee closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug.
Projects
None yet
Development

No branches or pull requests

2 participants