SuperHouse / esp-open-rtos

Open source FreeRTOS-based ESP8266 software framework
BSD 3-Clause "New" or "Revised" License
1.54k stars 490 forks source link

write() to a socket freezes #496

Open imihajlow opened 6 years ago

imihajlow commented 6 years ago

Hi all,

I'm not filing a bug here (I guess, you are not the addressee), but I would like to ask if anyone faced this problem and has a workaround.

I'm writing a software which uses HTTP and HTTPS (via BearSSL). And sometimes writing to a socket freezes forever. I've figured out that this happens more often with large input buffers. I've implemented a workaround to feed write() with smaller pieces of data, and it worked fine until recently I've added a new task.

Does anyone here understands what is going on, how sockets are internally implemented and if a stable workaround exists? Maybe there's a way to check for free "socket buffer memory"?

ourairquality commented 6 years ago

Socket descriptor 2 is not a valid lwip socket number but a write should have returned -1. The write() operation dispatches to lwip_write() in core/newlib_syscalls.c so it looks like an issue in lwip so look there. Perhaps a timeout needs to be defined or error handling improved etc. Lwip has a lot of debug output that can be enabled.

gpreviato commented 6 years ago

I experienced a similar problem, but the reason was related to the heap becoming too small and unable to allocate some memory. Malloc failed silently somewhere, and the socket stuck...

imihajlow commented 6 years ago

@gpreviato that's exactly what I've figured out. My workaround is to reduce heap usage.