Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosing heap #13

Open
dexterkhm opened this issue Oct 23, 2015 · 19 comments
Open

Loosing heap #13

dexterkhm opened this issue Oct 23, 2015 · 19 comments

Comments

@dexterkhm
Copy link

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?

@Caerbannog
Copy link
Owner

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).

@dexterkhm
Copy link
Author

Yes url is the same, it is Thingspeak. And I am connecting by domain name.

@Caerbannog
Copy link
Owner

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.

@vowstar
Copy link
Contributor

vowstar commented Oct 30, 2015

Try use espconn_delete(conn) before os_free(conn)
// Fix memory leak.
espconn_delete(conn);
os_free(conn);

@Caerbannog
Copy link
Owner

@dexterkhm Does the fix_memleak branch solve the problem?

@dexterkhm
Copy link
Author

I will try today.

@dexterkhm
Copy link
Author

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.

Caerbannog added a commit that referenced this issue Nov 8, 2015
Try to fix the leak reported in issue #13. Credit to @vowstar.
@dexterkhm
Copy link
Author

I Think problem with heap losing happens when two "http_get" called from different places at same time.

@vowstar
Copy link
Contributor

vowstar commented Dec 25, 2015

@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

@dexterkhm
Copy link
Author

Nice!!! how can I download fixed files??

@vowstar
Copy link
Contributor

vowstar commented Dec 25, 2015

@dexterkhm
The temporary URL of fixed files is here:
https://github.com/vowstar/esphttpclient

@dexterkhm
Copy link
Author

#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?

@vowstar
Copy link
Contributor

vowstar commented Dec 25, 2015

@dexterkhm This is to take care of some super slow servers and networks :)

@vowstar
Copy link
Contributor

vowstar commented Dec 25, 2015

@dexterkhm if 10 sec is ticking while you "http_get" again, you may get 2 reponses(callbacks)

@dexterkhm
Copy link
Author

Please try your code in 2-3 seconds "http_get" request period while server is stuck. And what happens with heap at this time?

@vowstar
Copy link
Contributor

vowstar commented Dec 25, 2015

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.

@dexterkhm
Copy link
Author

Ok thanks a lot. I will try now.

@vowstar
Copy link
Contributor

vowstar commented Dec 25, 2015

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);

@dexterkhm
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants