Loosing heap
dexterkhm opened this issue · 19 comments
Hello for a start thanks a lot for your useful code. But I have a problem, when I call "http_get" function too often (less than one second period) i am loosing heap of esp8266 and if "http_get" period bigger than a second everything is ok. Give me a suggestion what to do?
I'm not sure, I don't have an ESP toolchain anymore. Maybe this is inherent to having too many concurrent requests? Would rate-limiting after more than N=5 simultaneous requests be okay for you application?
Or maybe the rate limiting is due to the server side. Are all of your requests done to the same URL? You can try connecting to lots of IPs to see if the problem disappears (213.152.1.81, 213.152.1.82, ... for Google servers).
Yes url is the same, it is Thingspeak. And I am connecting by domain name.
OK.
It is possible that when thingspeaks receives so many requests it throttles them. The requests take longuer, maybe never finish, so the heap grows.
I suggest trying to temporarily remove the thingspeak domain, instead cycling between a lot of different domains (or IP addresses). This will show if the problem comes from server side throttling.
Try use espconn_delete(conn) before os_free(conn)
// Fix memory leak.
espconn_delete(conn);
os_free(conn);
@dexterkhm Does the fix_memleak branch solve the problem?
I will try today.
After half a day of testing I am still losing heap. But steps of stable values of heap become longer. It takes about 1 hour of stable heap value then I loose 300 bytes and after come another 1 hour of stable heap value.
I Think problem with heap losing happens when two "http_get" called from different places at same time.
@dexterkhm
I found when server is in debug mode or have no response in half way will caused memory leak.
So I add a timeout method to http request, when server timeout, it will recycle memory automatically.
Please try this.
#15
Nice!!! how can I download fixed files??
@dexterkhm
The temporary URL of fixed files is here:
https://github.com/vowstar/esphttpclient
#define HTTP_REQUEST_TIMEOUT_MS (10000) 10seconds??? O_o It is too long as I think. I am struggling now for 3 seconds period. And what happens If I "http_get" it again from somewhere while those 10 sec still ticking?
@dexterkhm This is to take care of some super slow servers and networks :)
@dexterkhm if 10 sec is ticking while you "http_get" again, you may get 2 reponses(callbacks)
Please try your code in 2-3 seconds "http_get" request period while server is stuck. And what happens with heap at this time?
In first 10 sec, the heap is decreasing, after 10s, the heap is stable, and when stop http request, the heap is increasing, and then recover, looks like nothing happend.
Ok thanks a lot. I will try now.
Note the http_post API is changed, http header is before http body, and http_delete and http_put have same interface as http_post
void http_post(const char * url, const char * post_data, const char * headers, http_callback user_callback);
changed to
void http_post(const char * url, const char * headers, const char * post_data, http_callback_t callback_handle);
See also
void http_get(const char * url, const char * headers, http_callback_t callback_handle);
void http_delete(const char * url, const char * headers, const char * post_data, http_callback_t callback_handle);
void http_put(const char * url, const char * headers, const char * post_data, http_callback_t callback_handle);
I add just your timer func arm and disarm lines, timer callback, added timer var into a structure. And run it .... Well after an while of fast transmite (two timers 3000ms and 15000ms both with httpget)- I still loosing heap that caused with reboot http://s011.radikal.ru/i318/1512/fe/cc45808676c7.jpg