Skip to content

HTTPClient doesn't respect CNAME TTL #9123

Open
@oSquat

Description

@oSquat

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP8266
  • Core Version: ??? Arduino IDE 2.3.2 2024-02-20T09:54:08669Z ???
  • Development Env: Arduino IDE
  • Operating System: Debian 11

Settings in IDE

  • Module: Wemos D1 mini (clone)
  • Flash Mode: ???
  • Flash Size: ???
  • lwip Variant: ???
  • Reset Method: ???
  • Flash Frequency: ???
  • CPU Frequency: ???
  • Upload Using: Serial
  • Upload Speed: 921600

Problem Description

I am sending web requests to systems which are configured for failover using CNAME records with low TTL values which point to A records with higher values. For example, I have 4 DNS records:

  • myproject.example.com CNAME TTL 60 -> node1.example.com (primary)
  • myproject.example.com CNAME TTL 60 -> node2.example.com (secondary)
  • node1.example.com A TTL 86400 203.0.113.1
  • node2.example.com A TTL 86400 198.51.100.2

I am expecting the TTL of both records to be respected. When the CNAME expires a new lookup should be performed.

In practice, the esp8266 library appears to ignore the CNAME TTL and a new lookup is performed only when the underlying A record expires.

Sketch

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

void setup() {
  WiFi.begin("TheSSID", "ThePSK");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print('.');
  }
}

void webRequest() {
  WiFiClient client;
  HTTPClient http;
  if (http.begin(client, "http://myproject.example.com/useful_endpoint/")) {
    int httpCode = http.GET();
    if (httpCode > 0) {
        Serial.printf("[HTTPS] GET status code: %d\n", httpCode);
    } else {
        Serial.printf("[HTTPS] GET failed; status code: %d)\n", httpCode);
    }
    http.end();
  } else {
    Serial.print("connection failed");
  }
}

void loop() {
  delay(5000);
  webRequest();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions