close() does not really release the fd which is created by socket()
Posted: Mon Oct 28, 2024 2:09 pm
I use or to create UDP/TCP socket, then bind(), then recv()/recvfrom() in a FreeRTOS task, then vTaskDelete(the recv task) and close() it in another FreeRTOS task, whatever it is a TCP or UDP, seems the fd seems never be released after close().
I can see the new fd number for the new socket() still increasing, it can be from 58, 59, 60.... until 64, then no longer can make new socket() (errno 23, reached maximum fd).
Even I just create it and never really use it.
The code looks like
Then in another task
IDF version is 5.3.1, chip is ESP32C6.
Is it anything wrong with my code? Do I missed something for close/release the socket?
Thank you!
Code: Select all
socket(addrFamily, SOCK_DGRAM, ipProtocol);
Code: Select all
socket(addrFamily, SOCK_STREAM, ipProtocol);
I can see the new fd number for the new socket() still increasing, it can be from 58, 59, 60.... until 64, then no longer can make new socket() (errno 23, reached maximum fd).
Even I just create it and never really use it.
The code looks like
Code: Select all
sock = socket(addrFamily, SOCK_DGRAM, ipProtocol);
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout);
int err = bind(sock, (struct sockaddr *)&destAddr, sizeof(destAddr));
recvfrom(sock, rxBuffer, sizeof(rxBuffer) - 1, 0, (struct sockaddr *)&sourceAddr, &socklen);
//--------This task is being blocking since there are no incoming data--------
Code: Select all
vTaskDelete(the above task handler);
close(sock);
Is it anything wrong with my code? Do I missed something for close/release the socket?
Thank you!