# API / HTTP Requests: DNS Implementation in the Farmbot, nxdomain issues, UDP vs. TCP

**URL:** <https://forum.farmbot.org/t/api-http-requests-dns-implementation-in-the-farmbot-nxdomain-issues-udp-vs-tcp/9228>\
**Category:** Software\
**Created:** [July 9, 2024, 8:51pm UTC](https://forum.farmbot.org/t/api-http-requests-dns-implementation-in-the-farmbot-nxdomain-issues-udp-vs-tcp/9228 "2024-07-09T20:51:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![farmS1m](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/f/f04885/32.png) [@farmS1m](https://forum.farmbot.org/u/farmS1m)\
**Post date:** [July 9, 2024, 8:51pm UTC](https://forum.farmbot.org/t/api-http-requests-dns-implementation-in-the-farmbot-nxdomain-issues-udp-vs-tcp/9228/1 "2024-07-09T20:51:47Z")

</div>

Hi there,

My sequences sometimes fail due to DNS problems. Seeing errors like these in the logs:  
`{:error, :nxdomain}`

The root cause is probably my unstable Wifi network since my Farmbot is behind a repeater this might be not ideal… 🧐

Anyway, I’m thinking of many users may could have similar issues, since DNS queries are made with UDP. Lost packets will never be returned to the Farmbot.

Would it may be possible to implement a new setting to switch DNS to TCP based DNS. I found this article it probably can be done easily in the resolve.conf: [domain name system - how to configure Linux to use TCP for DNS queries? - Server Fault](https://serverfault.com/questions/762003/how-to-configure-linux-to-use-tcp-for-dns-queries)

Another thing would be to enable some sort of DNS caching… But this could be not ideal for DNS Loadbalancing…

By the way: Is it possible to do a packet capture on the raspberry it self?  
Today I made a trace on my router, and I saw (I’m using plant group location based sequences), on each iteration a new DNS query is made. The router replied to all of them, but shortly before I stopped the trace, I got the “nxdomain” error. It must have been some sort of fatal error since the whole sequence stopped in the first quarter of processing 70 plants.

Errors:

 ![image](https://forum.farmbot.org/uploads/default/original/2X/f/fbc69ac601ade27f2714c9930582da671b8f3c9f.png)

Wireshark printscreen:

 ![image](https://forum.farmbot.org/uploads/default/original/2X/0/0e1ff82ead111ffeded047673c5e67a2c4b285db.jpeg)

---

<div class="post-metadata">

**Author:** ![jsimmonds](https://forum.farmbot.org/user_avatar/forum.farmbot.org/jsimmonds/32/1470_2.png) [@jsimmonds](https://forum.farmbot.org/u/jsimmonds)\
**Post date:** [July 10, 2024, 3:15am UTC](https://forum.farmbot.org/t/api-http-requests-dns-implementation-in-the-farmbot-nxdomain-issues-udp-vs-tcp/9228/2 "2024-07-10T03:15:01Z")

</div>

> [@farmS1m](#):
>
> but shortly before I stopped the trace, I got the “nxdomain” error.

Does that Wireshark screen shot capture those FBOS errors at 22:04 ?

> [@farmS1m](#):
>
> enable some sort of DNS caching…

I’m not convinced that your router DNS is to blame for these **`:nxdomain`** errors (?)  
It seems to reliably return DNS query responses in under 10ms.  
Are you thinking that some UDP response packets are not arriving over the Wi-Fi connection to FBOS ?

> [@farmS1m](#):
>
> Is it possible to do a packet capture on the raspberry it self?

Potentially, yes. You will need to add **tcpdump** to the FBOS Linux build (Buildroot Linux forum should have the ‘how to’ details), then make your custom **farmbot\_system\_rpi3-portable-1.23.1-farmbot.1** package and use that in your FBOS build.  
It should also be possible (if you can get a compatible **tcpdump** executable + required SO libraries) to sftp those to **/tmp** and run them from there. This requires you to have a custom FBOS build which include **ssh** support (not hard).

You might need to balance the effort of setting up DNS over TCP/HTTPS versus running a wired Ethernet connect to the bot. (Easy to do with Ethernet over Powerline devices)

Edit:  
@farmS1m the FBOS low-level DNS code uses Erlang OTP modules. You can examine their code to see what timers might be used before that **`:nxdomain`** failure is asserted.

Edit:  
@farmS1m I looked in the FBOS code but did not find **“Error during Metadata creation - See logs [. . .]”**?

 ![image](https://forum.farmbot.org/uploads/default/original/2X/a/a9dd0d7590a3a61bcfec53818b9a0cdf437ea1e8.png)

---

<div class="post-metadata">

**Author:** ![farmS1m](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/f/f04885/32.png) [@farmS1m](https://forum.farmbot.org/u/farmS1m)\
**Post date:** [July 10, 2024, 9:13am UTC](https://forum.farmbot.org/t/api-http-requests-dns-implementation-in-the-farmbot-nxdomain-issues-udp-vs-tcp/9228/3 "2024-07-10T09:13:57Z")

</div>

> [@jsimmonds](#):
>
> Does that Wireshark screen shot capture those FBOS errors at 22:04 ?

Yes the trace has been started at 21:46, and run for 19 minutes. I stopped the trace shortly after the issue occured.

> [@jsimmonds](#):
>
> Are you thinking that some UDP response packets are not arriving over the Wi-Fi connection to FBOS ?

Yes thats what I’m thinking of. Therefore I might will either try to setup a rpi image with tcpdump, or will consider to use a Powerline 😐

> [@jsimmonds](#):
>
> I looked in the FBOS code but did not find **“Error during Metadata creation - See logs [. . .]”**?

Thats correct it is a custom log message from my code:

```auto
plant = variable("Plant")
plant_id = plant.id
plant_url = "/api/points/" .. plant_id 
watered_last_amount = tonumber(env("watered_last_amount"))

-- toast(plant_id)
-- toast(plant_url)

result = api({
    method = "put",
    url = plant_url,
    body = {
        meta = {
            watered_last = local_time("date"),
            watered_last_timestamp = tostring(os.time()),
            watered_last_amount = watered_last_amount
        }
    }
})

if result then
    -- toast("Metadata creation ok", "debug")
else
    send_message("error", "Error during Metadata creation - See logs for details", "email")
end

api_result = api({method = "GET", url = plant_url})
result = json.encode(api_result)
-- send_message("info", result)

```

From the trace it is hard to say at least it looks like the FB did a request after the last DNS query seen in the trace. Probably the next dns query done from FB is not included in the trace, as It never got transported to the router. I don’t know.

 ![image](https://forum.farmbot.org/uploads/default/original/2X/0/08e8e65b2eab3da4f9402a357ea98eaa90459feb.jpeg)

Thank you so much for your helpful ideas! 😃

---

<div class="post-metadata">

**Author:** ![jsimmonds](https://forum.farmbot.org/user_avatar/forum.farmbot.org/jsimmonds/32/1470_2.png) [@jsimmonds](https://forum.farmbot.org/u/jsimmonds)\
**Post date:** [July 11, 2024, 6:11am UTC](https://forum.farmbot.org/t/api-http-requests-dns-implementation-in-the-farmbot-nxdomain-issues-udp-vs-tcp/9228/4 "2024-07-11T06:11:45Z")

</div>

> [@farmS1m](#):
>
> Probably the next dns query done from FB is not included in the trace, as It never got transported to the router. I don’t know.

Ask Wireshark to display absolute timestamps . . assume your router is nicely NTP synchronized (?)

Maybe another capture which completely covers a “ **`:nxdomain`** ” occurrence will show us bigger clues.

Edit: P.S. I also 💕 Wireshark 🙂

---

<div class="post-metadata">

**Author:** ![farmS1m](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/f/f04885/32.png) [@farmS1m](https://forum.farmbot.org/u/farmS1m)\
**Post date:** [July 12, 2024, 8:22am UTC](https://forum.farmbot.org/t/api-http-requests-dns-implementation-in-the-farmbot-nxdomain-issues-udp-vs-tcp/9228/5 "2024-07-12T08:22:52Z")

</div>

Getting one step closer. The setting to display absolute timestamps in Wireshark has helped a lot! I was able to pin it to 22:04 (UTC 20:04).

It looks like the FB received a new DHCP offer at that time. Probably because the Wi-Fi Adapter lost its signal and recovered from it a few minutes later. Unfortunately my trace was made with a host filter (of the FB IP), therefore I do not see the DHCP request from the FB with origin IP 0.0.0.0.

 ![image](https://forum.farmbot.org/uploads/default/original/2X/8/850c536644ddca88a6816826dd06b2c452310cf7.jpeg)

I think this is proof enough, my Wi-Fi is still 💩 (Even I already have installed a repeater, the signal strength fluctuates between 36 - 84%! This is quite bad, but think the shutter blinds have some impact or some neighbors 😉 Another thing could be some random channel auto reconfiguration. Will might check some repeater / router logs according to this.

@jsimmonds Do you know if a total loss of the Wi-Fi signal would be logged somewhere?

---

<div class="post-metadata">

**Author:** ![jsimmonds](https://forum.farmbot.org/user_avatar/forum.farmbot.org/jsimmonds/32/1470_2.png) [@jsimmonds](https://forum.farmbot.org/u/jsimmonds)\
**Post date:** [July 14, 2024, 7:57am UTC](https://forum.farmbot.org/t/api-http-requests-dns-implementation-in-the-farmbot-nxdomain-issues-udp-vs-tcp/9228/6 "2024-07-14T07:57:46Z")

</div>

> [@farmS1m](#):
>
> @jsimmonds Do you know if a total loss of the Wi-Fi signal would be logged somewhere?

Don’t know but will dig around . . **wpa\_supplicant** on the FBOS Linux is managed by Elixir app **`:vintage_net_wifi`** and relations. There should be logging that we could see or enable.

Just thinking bigger-picture about the **:nxdomain** abort from HTTP Client here

- Should DNS client query requests normally be re-tried n-times on response **timeout**?
- Are there other signs in latest **Wireshark** capture that indicate a loss of **internet** apart from **`18.205.222.128`** unexpectedly **REJ** ecting ?

What I’m wondering is whether **AWS** load-balancing is working correctly ?

Edit: My mistake there: If NO Internet then **AWS** _cannot_ **REJ** ect 😊  
Edit: Ooops; TCP Header has no **REJ** flag, only **RST** 😊

---

<div class="post-metadata">

**Author:** ![farmS1m](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/f/f04885/32.png) [@farmS1m](https://forum.farmbot.org/u/farmS1m)\
**Post date:** [July 14, 2024, 9:21pm UTC](https://forum.farmbot.org/t/api-http-requests-dns-implementation-in-the-farmbot-nxdomain-issues-udp-vs-tcp/9228/7 "2024-07-14T21:21:31Z")

</div>

At the moment (at least today) I was not able to reproduce the issue. But I expect it to be back in a few days and will do a new trace.

The strange thing is I didn’t had the **:nxdomain** in the wireshark trace. So I’m also asking myself who responds with :nxdomain…

> [@jsimmonds](#):
>
> Are there other signs in latest **Wireshark** capture that indicate a loss of **internet** apart from **`18.205.222.128`** unexpectedly **REJ** ecting ?

I think in general it looks good. For some reason all the connection went all the time to 18.205.222.128, asking myself if the DNS roundrobin even works…

 ![image](https://forum.farmbot.org/uploads/default/original/2X/7/717acc09abf7c3d3f50b60607ba8f4165cf45a8b.jpeg)

Sent you the trace via PN, if you wan’t to have a look 🤓

---

<div class="post-metadata">

**Author:** ![jsimmonds](https://forum.farmbot.org/user_avatar/forum.farmbot.org/jsimmonds/32/1470_2.png) [@jsimmonds](https://forum.farmbot.org/u/jsimmonds)\
**Post date:** [July 15, 2024, 6:40am UTC](https://forum.farmbot.org/t/api-http-requests-dns-implementation-in-the-farmbot-nxdomain-issues-udp-vs-tcp/9228/8 "2024-07-15T06:40:20Z")

</div>

> [@farmS1m](#):
>
> Sent you the trace via PN, if you wan’t to have a look 🤓

Taking a look now 🙂 First impressions are

- That **:nxdomain** error is likely coming from the **:hackney** HTTP client package and you will never see that “on the wire”
- Your Wi-Fi is stable enough.
- I’m following several conversations between FBOS and 18.205.222.128 trying to understand how they end. ( **:hackney** uses a pool of HTTPS clients) TCP Keepalive seems to be enabled at the AWS end.

---

<div class="post-metadata">

**Author:** ![system](https://forum.farmbot.org/user_avatar/forum.farmbot.org/system/32/4564_2.png) [@system](https://forum.farmbot.org/u/system)\
**Post date:** [August 14, 2024, 6:40am UTC](https://forum.farmbot.org/t/api-http-requests-dns-implementation-in-the-farmbot-nxdomain-issues-udp-vs-tcp/9228/9 "2024-08-14T06:40:40Z")

</div>

Closed on August 14, 2024, 6:40am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
