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

Send UDP package to server, but server got UDP package with wrong size. #9833

Open
1 task done
fryefryefrye opened this issue Jun 12, 2024 · 3 comments
Open
1 task done
Labels
Area: WiFi Issue related to WiFi

Comments

@fryefryefrye
Copy link

Board

ESP32_S2

Device Description

An ESP32_S2 Mini board

Hardware Configuration

N/A

Version

v2.0.14

IDE Name

platformio

Operating System

Win 7

Flash frequency

40Mhz

PSRAM enabled

yes

Upload speed

115200

Description

While running for days.
The following will happen occasionally

Receive side got UDP package with wrong size.
Got UDP size of 40.
One second later, got UDP size of 60.
One second later, got UDP size of 80.
One second later, got UDP size of 100.
One second later, got UDP size of 120.
................

Sketch

void loop()
{
    delay(1000)
    m_WiFiUDP.beginPacket("xxx.com", 5050);
    m_WiFiUDP.write((const uint8_t *)&SomeData, 20);
    m_WiFiUDP.endPacket();
}

Debug Message

log_e("could not get host from dns: %d", errno);

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@fryefryefrye fryefryefrye added the Status: Awaiting triage Issue is waiting for triage label Jun 12, 2024
@fryefryefrye
Copy link
Author

fryefryefrye commented Jun 12, 2024

The same code used on ESP8266 never have problem.

But on ESP32, when there is some trouble on DNS lookup, and the result of "beginPacket" is not checked.
I think it will lead UDP stack with dirt data and cause the DNS lookup always failed.

The following code will fix this problem, but maybe some update is need is better for users. Because I spend month to catch the reason.

void loop()
{
    delay(1000)
    if (m_WiFiUDP.beginPacket("xxx.com", 5050))
    {
        m_WiFiUDP.write((const uint8_t *)&SomeData, 20);
        m_WiFiUDP.endPacket();
    }
}

The root reason caused this problem.

C:\Users\xxx.platformio\packages\framework-arduinoespressif32\libraries\WiFi\src\WiFiUdp.cpp
line 168

int WiFiUDP::beginPacket(const char *host, uint16_t port){
  struct hostent *server;
  server = gethostbyname(host);
  if (server == NULL){
    log_e("could not get host from dns: %d", errno);
    return 0;
  }
  return beginPacket(IPAddress((const uint8_t *)(server->h_addr_list[0])), port);
}

@VojtechBartoska VojtechBartoska added Area: WiFi Issue related to WiFi and removed Status: Awaiting triage Issue is waiting for triage labels Jun 12, 2024
@VojtechBartoska
Copy link
Collaborator

@me-no-dev can you please take a look? thanks

@me-no-dev
Copy link
Member

Please try with 3.0.1

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

No branches or pull requests

3 participants