ESP32 Socket error 23

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
pinazawa
Posts: 8
Joined: Thu Apr 25, 2019 1:13 pm

ESP32 Socket error 23

Post by pinazawa » Thu Apr 25, 2019 7:08 pm

Hello everyone!

I'm having an issue with an application I'm developing using an ESP32 WROOM. The problem is the following: I'm trying to open a socket and communicate to a remote server that is offline during a certain period of time (from 06 AM to 06 PM).

When the server is online, everything works perfectly. But during the offline time, I adopted the strategy of pooling the socket connection in a try except structure. In the first tries, the socket works fine, returning errors such as TIMEOUT (which are very understandable, since the server is offline).

However, within 10 minutes of trying connecting, the return of the socket connection changes to 'OSError: 23'. According to many sources (such as this one: http://www.ioplex.com/~miallen/errcmp.html ), this kind of error is related to 'Too many files open in system' . In this state, even when the server is online, the sockets never connect within the loop I did, and only a machine.reset() can return it to normal state.

I already tried even deleting the entire sock object that was created whenever I get this error, but is useless.

Is there a better way to handle this problem?

Is there a place where I can see the opened sockets inside Micropython, so I can close them? Or maybe reset All sockets without applying a global hard reset?

Pedro.

pinazawa
Posts: 8
Joined: Thu Apr 25, 2019 1:13 pm

Re: ESP32 Socket error 23

Post by pinazawa » Thu Apr 25, 2019 7:19 pm

Just adding some info:

I have GC enabled in the code, and I have tried opening the sock and closing it afterward, and also creating the socket and deleting it from memory (using del sockobj). Both way enter the OsError 23 in the loop, although they should only return ETIMEOUT or something similar...

pinazawa
Posts: 8
Joined: Thu Apr 25, 2019 1:13 pm

Re: ESP32 Socket error 23

Post by pinazawa » Tue Jun 11, 2019 7:30 pm

I Think I figured it out: My ESP32 was running out of RAM memory.

I printed the memory at each iteraction, and each time the memory was critically low, my esp32 started to throw error 23.

I eliminated many counters and other RAM consumers, and apparently it came back to normality.

I will update here, if anything goes wrong again.

vpatron
Posts: 1
Joined: Thu Jan 19, 2017 12:30 am

Re: ESP32 Socket error 23

Post by vpatron » Mon Nov 15, 2021 4:13 pm

I know I'm replying to an old post, but in case anyone is looking, I think had a similar problem on ESP8266

I made my code more solid by making sure to close the socket if I had any kind of error during setup and after an http request was complete. I think not calling .close() will leave resources open and eventually run out of memory.

Post Reply