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

Deno 2.1.5 regressions with DNS regarding axios (due to node compat change) #27670

Open
hourianto opened this issue Jan 14, 2025 · 6 comments
Open
Assignees

Comments

@hourianto
Copy link

hourianto commented Jan 14, 2025

Noticed that some of my scripts started failing after I upgraded to 2.1.5.

This replicates part of the issue:

import axios from "npm:axios"

async function makeRequest(): Promise<void> {
  try {
    await axios.get("https://test.openai.azure.com")
  } catch (error) {
    console.error(new Date().toISOString(), axios.isAxiosError(error) ? error.message : error)
  }
}

async function main(): Promise<void> {
  const batchSize = 5

  while (true) {
    await Promise.all(Array(batchSize).fill(null).map(() => makeRequest()))
    await new Promise((resolve) => setTimeout(resolve, 1000))
  }
}

main().catch((error) => console.error("Error:", error))

With this script I'm getting random logs like:

dropped malformed message waiting for id: 45650 err: unexpected end of input reached
dropped malformed message waiting for id: 26004 err: unexpected end of input reached
dropped malformed message waiting for id: 35252 err: unexpected end of input reached
dropped malformed message waiting for id: 33116 err: unexpected end of input reached
dropped malformed message waiting for id: 25559 err: unexpected end of input reached
dropped malformed message waiting for id: 36211 err: unexpected end of input reached
dropped malformed message waiting for id: 28699 err: unexpected end of input reached

In my real script (sadly I cannot publish that code) I also get those random errors. In short, the real code does lots of requests each second to different domains some of which don't exist anymore, but most do:

dropped malformed message waiting for id: 54215 err: rdata length too large for remaining bytes, need: 4 remain: 3
dropped malformed message waiting for id: 34012 err: rdata length too large for remaining bytes, need: 4 remain: 1
dropped malformed message waiting for id: 31268 err: rdata length too large for remaining bytes, need: 4 remain: 1
dropped malformed message waiting for id: 62347 err: unexpected end of input reached
dropped malformed message waiting for id: 42106 err: unexpected end of input reached
dropped malformed message waiting for id: 62387 err: unexpected end of input reached

Second case (I discovered this by accident):

import axios from "npm:axios"

async function main(): Promise<void> {
  try {
    const response = await axios.get("https://doesntexist213659tetee.com")
  } catch (error) {
    if (axios.isAxiosError(error)) {
      console.error(`Failed with error: ${error.message}`)
    } else {
      console.error(`Unexpected error: ${error}`)
    }
  }
}

await main()
console.log("caught it")

With Deno 2.1.4 and below this runs properly and outputs "caught it" (since it catches the error), with 2.1.5 I get a hard crash (that does not get caught by the catch):

error: Uncaught Error: getaddrinfo ENOTFOUND doesntexist213659tetee.com
    at __node_internal_captureLargerStackTrace (ext:deno_node/internal/errors.ts:93:9)
    at __node_internal_ (ext:deno_node/internal/errors.ts:246:10)
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:43:26)
    at ext:deno_node/internal_binding/cares_wrap.ts:71:9
    at eventLoopTick (ext:core/01_core.js:175:7)

With native fetch everything works fine.

#27642 might have the same root cause

@kt3k kt3k self-assigned this Jan 14, 2025
@kt3k
Copy link
Member

kt3k commented Jan 15, 2025

dropped malformed message waiting for id: 45650 err: unexpected end of input reached
dropped malformed message waiting for id: 26004 err: unexpected end of input reached
dropped malformed message waiting for id: 35252 err: unexpected end of input reached
dropped malformed message waiting for id: 33116 err: unexpected end of input reached

Do you see these error messages with exactly the above example, or do you modify the URL part?

If I ran the first example, I saw the errors like:

$ deno -A a.ts
2025-01-15T07:57:35.165Z Request failed with status code 404
2025-01-15T07:57:35.169Z Request failed with status code 404
2025-01-15T07:57:35.169Z Request failed with status code 404
2025-01-15T07:57:35.169Z Request failed with status code 404
2025-01-15T07:57:35.169Z Request failed with status code 404
2025-01-15T07:57:36.542Z Request failed with status code 404
2025-01-15T07:57:36.544Z Request failed with status code 404

which is the same as what Node.js shows.

Second case (I discovered this by accident):

This case seems a regression in 2.1.5. I'll work on it.


Note: We changed the internal implementation of Node compat http(s).request in 2.1.5 (#25470). In the new implementation we started using dns.lookup for resolving domain names, and this is probably related to it.

I guess probably our dns resolver (It internally uses Deno.resolveDns which internally uses hickory-dns) is now too strict about handling dns data.

The error message is likely from here https://github.com/hickory-dns/hickory-dns/blob/b942d68020ee6f88bbd459812c5fab22b748413c/crates/proto/src/udp/udp_client_stream.rs#L318

@hourianto
Copy link
Author

hourianto commented Jan 15, 2025

@kt3k for the first case - yeah, I see errors in the console with that exact code. It takes some time to get them though, a few seconds perhaps. This is what dig returns for that domain:

test.openai.azure.com.  900     IN      CNAME   koreacentral.api.cognitive.microsoft.com.
koreacentral.api.cognitive.microsoft.com. 3600 IN CNAME cognitivekcprod.trafficmanager.net.
cognitivekcprod.trafficmanager.net. 30 IN CNAME cognitivekcprod.azure-api.net.
cognitivekcprod.azure-api.net. 900 IN   CNAME   apimgmttm6jlrkljhsnxfyj4ybmjxuinaoxgxjlz8tpdomzoya.trafficmanager.net.
apimgmttm6jlrkljhsnxfyj4ybmjxuinaoxgxjlz8tpdomzoya.trafficmanager.net. 300 IN CNAME cognitivekcprod-koreacentral-01.regional.azure-api.net.
cognitivekcprod-koreacentral-01.regional.azure-api.net. 900 IN CNAME apie98ecb42422c43a49d717dbbb805352ekhsube4o75jbgtwcyzkxp.koreacentral.cloudapp.azure.com.
apie98ecb42422c43a49d717dbbb805352ekhsube4o75jbgtwcyzkxp.koreacentral.cloudapp.azure.com. 10 IN A 20.194.72.197

@kt3k
Copy link
Member

kt3k commented Jan 15, 2025

Do you see the same error (dropped malformed message waiting for id: 45650 err: unexpected end of input reached) when executing the below script?

console.log(await Deno.resolveDns("test.openai.azure.com.", "A"));

@hourianto
Copy link
Author

Hmm, no, if I do this (even in a loop or multiple concurrent ones), it's all fine. Is there a way I can understand why I'm getting all those console errors? I could build Deno if needed

@kt3k
Copy link
Member

kt3k commented Jan 15, 2025

Sounds very strange situation to me..

axios uses node:https.request which uses node:dns.lookup which uses Deno.resolveDns. So can you also check if the issue reproduces with the below scripts? (This should narrow where the issue exists)

import dns from "node:dns"
dns.lookup("test.openai.azure.com", console.log);
import https from "node:https"
https.request("https://test.openai.azure.com", console.log).end()

@hourianto
Copy link
Author

hourianto commented Jan 15, 2025

Yeah, I get the error with the first snippet, but it's inconsistent. Sometimes it just gives the IP straight away, sometimes it does this:

dropped malformed message waiting for id: 62340 err: unexpected end of input reached
dropped malformed message waiting for id: 24232 err: unexpected end of input reached
null 20.194.72.197 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants