DNS Error when using Fetch API only in Railway
I wrote a crawler using the crawlbase api. It runs fine in a container on my local machine, but in railway, it seems like im getting some kind of dns error.
Container Base: node:18.16-alpine
Its just a basic node + typescript application.
Here is an example of how im fetching.
The error looks something like this
Not really sure why this is and wanted to make sure there aren't any internal dns gotchas
Solution:Jump to solution
I wrote a crawler using the crawlbase api. It runs fine in a container on my local machine, but in railway, it seems like im getting some kind of dns error.
Container Base: node:18.16-alpine
Its just a basic node + typescript application.
...
10 Replies
Project ID:
764096d4-61ee-4d50-af38-6a9a0eda6dd7
764096d4-61ee-4d50-af38-6a9a0eda6dd7
dns lookup for that domain is taking over 5 seconds on railway for some reason
https://utilities.up.railway.app/dns-lookup?value=api.crawlbase.com&type=ip
Oh.... that is super weird. It would be nice it was that slow, but maybe I can do something in code to look up that dns record with a longer timeout and then cache it. Never missed with that in node so will have to look into it I guess
you can create a new resolver with a custom timeout set, but can you pass that into the fetch request?
or just create a resolver that uses 1.1.1.1
https://utilities.up.railway.app/dns-lookup?value=api.crawlbase.com&type=ip&dns=1.1.1.1
Oh, that is awesome. Thank you.
I was just about to test my solution. Didn't know that 1.1.1.1 was faster. I had to switch from fetch to to the https node library so that I could pass in a lookup function. Then I juse used a resolver with a large timeout there.
I'm also going to make sure that the resolver uses 1.1.1.1 as the dns server so its faster. Going to post code and mark as solved if this works
no timeout needed if you use 1.1.1.1 🙂
It seems like this works. You might be able to get away with just using dns.setServers(['1.1.1.1']) and the using fetch. I couldn't find a whole ton of documentation on that.
I ended up just ended up writing this request.ts file. Timeout is probably optional as well, but I wanted to make sure so I left it in.
Then I call it like this
Thanks for your help @Brody dns timeouts are fixed and its way faster after setting the servers
oops. I messed up linking the solution correctly. I see how that works now but don't know how to fix it
don't worry about it
I'm glad I could help