serverless-dns: DNS packet encode / decode unhandled exceptions

After adding a caching layer, reliance on dns-packet encoding / decoding has gone up. In our tests, these unhandled exceptions have cropped up in the meanwhile:

  "exceptions": [
    {
      "name": "TypeError",
      "message": "Failed to execute function: parameter 1 is not of type 'Response'.",
    }
  ],
  "logs": [
    {
      "message": [
        "Error At : DNSParserWrap -> Encode"
      ],
      "level": "error",
    },
    {
      "message": [
        "TypeError: e.copy is not a function\n    at Object.encode (worker.js:10:13483)\n    at Object.encode (worker.js:10:33416)\n    at ce (worker.js:10:35934)\n    at ne (worker.js:10:35051)\n    at de.Encode (worker.js:10:36285)\n    at Ue.dnsBlockResponse (worker.js:10:44687)\n    at vt.Rt (worker.js:10:82128)\n    at vt.executePlugin (worker.js:10:80457)\n    at async worker.js:10:82801"
      ],
      "level": "error",
    }
  ],
 "outcome": "exception",
  "scriptName": null,
  "exceptions": [
    {
      "name": "TypeError",
      "message": "Failed to execute function: parameter 1 is not of type 'Response'.",
    }
  ],
  "logs": [
    {
      "message": [
        "Error At : DNSParserWrap -> Encode"
      ],
      "level": "error",
    },
    {
      "message": [
        "TypeError: e.copy is not a function\n    at Object.encode (worker.js:10:13483)\n    at Object.encode (worker.js:10:33416)\n    at ce (worker.js:10:35934)\n    at ne (worker.js:10:35051)\n    at de.Encode (worker.js:10:36285)\n    at Ue.dnsBlockResponse (worker.js:10:44687)\n    at vt.Rt (worker.js:10:82128)\n    at vt.executePlugin (worker.js:10:80457)\n    at async worker.js:10:82801"
      ],
      "level": "error",
    }
  ],

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

some more from development instance. This happens routinely.

 2021-12-04T21:59:08.842 app[28243a82] maa [info] Error At : DNSParserWrap -> Decode
2021-12-04T21:59:08.843 app[28243a82] maa [info] RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 312. Received 430
2021-12-04T21:59:08.843 app[28243a82] maa [info] at new NodeError (node:internal/errors:371:5)
2021-12-04T21:59:08.843 app[28243a82] maa [info] at boundsError (node:internal/buffer:86:9)
2021-12-04T21:59:08.843 app[28243a82] maa [info] at Buffer.readUInt16BE (node:internal/buffer:332:5)
2021-12-04T21:59:08.843 app[28243a82] maa [info] at Object.question.decode (file:///node-dir/node_modules/@serverless-dns/dns-parser/index.js:1875:31)
2021-12-04T21:59:08.843 app[28243a82] maa [info] at decodeList (file:///node-dir/node_modules/@serverless-dns/dns-parser/index.js:1995:19)
2021-12-04T21:59:08.843 app[28243a82] maa [info] at Module.decode (file:///node-dir/node_modules/@serverless-dns/dns-parser/index.js:1935:12)
2021-12-04T21:59:08.843 app[28243a82] maa [info] at DNSParserWrap.Decode (file:///node-dir/node_modules/@serverless-dns/dns-operation/dnsParserWrap.js:17:24)
2021-12-04T21:59:08.843 app[28243a82] maa [info] at DNSBlock.RethinkModule (file:///node-dir/node_modules/@serverless-dns/dns-operation/dnsBlock.js:35:51)
2021-12-04T21:59:08.843 app[28243a82] maa [info] at RethinkPlugin.executePlugin (file:///node-dir/plugin.js:127:50)
2021-12-04T21:59:08.843 app[28243a82] maa [info] at runMicrotasks (<anonymous>)

2021-12-04T21:59:08.844 app[28243a82] maa [info] Error At : DNSBlock -> RethinkModule
2021-12-04T21:59:08.844 app[28243a82] maa [info] RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 312. Received 430
2021-12-04T21:59:08.844 app[28243a82] maa [info] at new NodeError (node:internal/errors:371:5)
2021-12-04T21:59:08.844 app[28243a82] maa [info] at boundsError (node:internal/buffer:86:9)
2021-12-04T21:59:08.844 app[28243a82] maa [info] at Buffer.readUInt16BE (node:internal/buffer:332:5)
2021-12-04T21:59:08.844 app[28243a82] maa [info] at Object.question.decode (file:///node-dir/node_modules/@serverless-dns/dns-parser/index.js:1875:31)
2021-12-04T21:59:08.844 app[28243a82] maa [info] at decodeList (file:///node-dir/node_modules/@serverless-dns/dns-parser/index.js:1995:19)
2021-12-04T21:59:08.844 app[28243a82] maa [info] at Module.decode (file:///node-dir/node_modules/@serverless-dns/dns-parser/index.js:1935:12)
2021-12-04T21:59:08.844 app[28243a82] maa [info] at DNSParserWrap.Decode (file:///node-dir/node_modules/@serverless-dns/dns-operation/dnsParserWrap.js:17:24)
2021-12-04T21:59:08.844 app[28243a82] maa [info] at DNSBlock.RethinkModule (file:///node-dir/node_modules/@serverless-dns/dns-operation/dnsBlock.js:35:51)
2021-12-04T21:59:08.844 app[28243a82] maa [info] at RethinkPlugin.executePlugin (file:///node-dir/plugin.js:127:50)
2021-12-04T21:59:08.844 app[28243a82] maa [info] at runMicrotasks (<anonymous>)
2021-12-04T21:59:08.844 app[28243a82] maa [info] {"isException":true,"exceptionStack":"RangeError [ERR_OUT_OF_RANGE]: The value of \"offset\" is out of range. It must be >= 0 and <= 312. Received 430\n at new NodeError (node:internal/errors:371:5)\n at boundsError (node:internal/buffer:86:9)\n at Buffer.readUInt16BE (node:internal/buffer:332:5)\n at Object.question.decode (file:///node-dir/node_modules/@serverless-dns/dns-parser/index.js:1875:31)\n at decodeList (file:///node-dir/node_modules/@serverless-dns/dns-parser/index.js:1995:19)\n at Module.decode (file:///node-dir/node_modules/@serverless-dns/dns-parser/index.js:1935:12)\n at DNSParserWrap.Decode (file:///node-dir/node_modules/@serverless-dns/dns-operation/dnsParserWrap.js:17:24)\n at DNSBlock.RethinkModule (file:///node-dir/node_modules/@serverless-dns/dns-operation/dnsBlock.js:35:51)\n at RethinkPlugin.executePlugin (file:///node-dir/plugin.js:127:50)\n at runMicrotasks (<anonymous>)","exceptionFrom":"DNSBlock RethinkModule","data":false} 

A GET Request is created by DoT handler, maybe I should revert it back to POST. If this happening because of URL length being too large. But I find that unlikely too.

Yes, locally upstream POST. Safer since POST can handle arbitrary sized requests.

I guess, we are long done with this one with all the recent changes and refactors.

Okay, making changes…

Could set 405 res code from command-control.

Currently there are no checks for request method I believe. What is not a GET is assumed to be POST.

CORS headers also set “Allow request methods” to all (*), it should be modified to be just POST & GET (and OPTIONS?)

One of the decoding errors was caused by this array buffer of upstream response:

6e 6f 20 64 6f 77 6e 73 74 72 65 61 6d 20 73 65 72 76 65 72 20 61 76 61 69 6c 61 62 6c 65

This is not a dns-packet. It is text that says: “no downstream server available”.

Searching the web shows this: https://github.com/PowerDNS/pdns/blob/f9f6a6257e43133d98a7295994d0a7c50b80e261/pdns/dnsdistdist/doh.cc#L400 Maybe what upstream (quad9 (10)) could be using.

Checking response code from upstream before decoding will probably reduce many of these errors.

Edit: It is 502 Response Code when this happens.

Error At : DNSParserWrap -> Decode
@DNSResolver->updateCache: Failed decoding response body buffer => resp code: 502 resp body buf: ArrayBuffer {
  [Uint8Contents]: <6e 6f 20 64 6f 77 6e 73 74 72 65 61 6d 20 73 65 72 76 65 72 20 61 76 61 69 6c 61 62 6c 65>,
  byteLength: 30
}
Error At : DNSResolver -> RethinkModule
RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 28. Received 123