Issue with using 1.1.1.1 as DNS

When I run a simple python program to fetch some data from any url, I get a delay of around 6 seconds.
For example:
import requests

print(requests.get("http://example.com").text)

This seems to happen because it queries both the A and AAAA record at the same time and I only get a response for the A record (which was queried first). After not getting the AAAA record it asks for both of the records again but in succession. If I use the proxy of my router I don't have said issue. The first screenshot attached to the post is Wireshark with the filter set to frame contains "example" .
If I specify for what type of TCPConnector to use e.g. with:
import aiohttp
import socket
import asyncio

async def fetch_data():
    connector = aiohttp.TCPConnector(family=socket.AF_INET6)
    async with aiohttp.ClientSession(connector=connector) as session:
        response = await session.get("https://www.example.com")
        return await response.text()


data = asyncio.run(fetch_data())
print(data)

It only asks for the AAAA record and I don't get any delay.
The second Screenshot is when I've used my router as my DNS. Another important thing to add is that I am using archlinux on kernel version 6.6.8.arch1-1. It would be nice to know if this is an issue caused by me which I am able to resolve by myself, if this is expected behaviour or an issue with the cloudflare DNS.
Thank you!
Was this page helpful?