TLS storing previous connection information

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: TLS storing previous connection information

Postby ESP_Angus » Tue Mar 07, 2017 12:57 am

This is just a possibility,but: When you close a TCP socket, LWIP needs to keep the socket around in the TIME_WAIT state until it knows the socket is closed at the other end.

This list shouldn't be bounded by size though, as far as I know it's only bounded by time. But if you are creating/deleting sockets on a regular basis, it may be that "10 sockets" is the amount of time it takes to timeout one socket.

slcasner
Posts: 17
Joined: Tue Dec 06, 2016 8:08 pm

Re: TLS storing previous connection information

Postby slcasner » Tue Aug 08, 2017 10:34 pm

The reason why 84 bytes are not freed when you close the socket is that LWIP allocates a mutex for use with each socket structure the first time the socket is opened and intentionally does not free that mutex. Look for the comment /* one time init and never free */ in esp-idf/components/lwip/api/sockets.c

The reason why this memory "leak" stops after the 10th time is that the default configuration (which you can change in menuconfig) provides space for 10 socket structures. LWIP follow as policy of not reusing a socket number and its associated structure so long as there is a never-used one still available. After all 10 have been used, then it will reuse one. In that case, the mutex will have already been allocated.

Who is online

Users browsing this forum: Baidu [Spider] and 142 guests