Skip to content

setNoDelay on ESP32 causing error [E][WiFiClient.cpp:309] setOption(): fail on fd -1, errno: 9, "Bad file number" #637

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

Closed
sivar2311 opened this issue Mar 9, 2021 · 4 comments
Labels

Comments

@sivar2311
Copy link
Contributor

Hi Markus,

on ESP32 it seems that setNoDelay(true) does not work and causing the "Bad file number" error when WebSocketsClient connects to a server.

setNoDelay(true) is called in connectedCb in WebSocketsClient.cpp:

#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
_client.tcp->setNoDelay(true);

I tried to follow the path to see where the error comes from, but I ended up in lwip_setsockopt_r in lwip.h

At this point my knowledge left me :(

I think the ESP32 should be removed from from the #if macro - what do you think?

@genemyers
Copy link

genemyers commented Mar 25, 2021

I'm experiencing exactly the same issue. If I fail to connect a few times after getting this message I then get an out of memory exception. It's my understanding that “Bad File Number” error (Errno: 9) in a multithreaded application error, an “Opened once but closed twice” bug. So when thread “Y” carries out its second close(), it actually closes the file descriptor of thread “X”, which was valid & in use. I'm not sure if this is what is causing my our of memory exception, but since setNoDelay(true) disables the Nagle algorithm, that intends to reduce TCP/IP traffic of small packets sent over the network by combining a number of small outgoing messages, and sending them all at once, I think Boris' suggestion is a good one.

@Links2004
Copy link
Owner

if the setNoDelay is problematic on the ESP32 in some use cases we can remove it via the macro.

@Links2004 Links2004 added the ESP32 label Apr 4, 2021
@Lackmann1994
Copy link

I'm facing the same issue.
How would you remove it via the macro?

@noorhaq
Copy link

noorhaq commented Sep 12, 2022

Hi Guys,
I am facing the same issue was it fixed?
If yes what was the fix.
I did remove the setnodelay from the macro but no effect on error.

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

No branches or pull requests

5 participants