http_client componets - function perform and memory problem

pdemianczuk
Posts: 28
Joined: Thu May 30, 2019 12:05 pm

http_client componets - function perform and memory problem

Postby pdemianczuk » Mon Dec 16, 2019 11:27 am

I used http_client_perform (from components http_client);
I need read many time this method from server. When I used it a noticed that my memory was losing.
Why it was happend?

Code: Select all

	   	esp_http_client_handle_t client2 = esp_http_client_init(&config);
		esp_http_client_set_method(client2, HTTP_METHOD_POST);
		esp_http_client_set_header(client2, "Cookie", ssid);
			err = 0;
	err = esp_http_client_set_post_field((esp_http_client_handle_t) *client2,  (const char *) param_send, size_send);
	printf("POST nr %d ERR = %d \n",run_client, err);
	check_ram();


	 if (heap_caps_get_free_size(MALLOC_CAP_8BIT)/1024 > 20)
	 {
		printf("**Perrforming  \n");
		err = esp_http_client_perform((esp_http_client_handle_t) *client2);

	}
	 else {
		 printf("**!NOT Perrforming  \n");
	 }
My config is

Code: Select all

   esp_http_client_config_t config = {
   	.host = ADRES_HOST,
   	.path = ADRES_PATH,
	.port = ADRES_PORT,
	.transport_type = HTTP_TRANSPORT_OVER_TCP,
	.buffer_size = 4*1024,
	 .event_handler = _http_event_handler,
	.is_async = false,
		   	    };
My log is:

Code: Select all

 I (8473) Check HEAP ... : free DRAM 151 kB 0x25ef8 | IRAM 209 kB 0x344a4 
       
I (8493) Check HEAP ... : free DRAM 142 kB 0x23aac | IRAM 200 kB 0x32058 
                                                                              
 f(): http_snd_frame2                                                                        
I (8503) Check HEAP ... : free DRAM 142 kB 0x23aac | IRAM 200 kB 0x32058 
I (8513) Check HEAP ... : free DRAM 142 kB 0x23aac | IRAM 200 kB 0x32058 
POST nr 1 ERR = 0                                                      
I (8513) Check HEAP ... : free DRAM 142 kB 0x23aac | IRAM 200 kB 0x32058     
                                               
**Perrforming                                                          
f() test_task    counter:    8                                          
I (8783) Check HEAP ... : free DRAM 142 kB 0x238e8 | IRAM 199 kB 0x31e94 
*CHECK TASK no: 1074322304       size: 448                             
 I (8853) Check HEAP ... : free DRAM 37 kB 0x969c | IRAM 95 kB 0x17c48 
*CHECK TASK no: 1074322304       size: 8144                            
                                                                              
   
I (8863) ~                       3927 ---> 3927                        
I (8873) Check HEAP ... : free DRAM 27 kB 0x6e98 | IRAM 85 kB 0x15444 
I (8873) Check HEAP ... : free DRAM 32 kB 0x8268 | IRAM 90 kB 0x16814   
*CHECK TASK no: 1074322304       size: 8144                            
                                                                       
-esp_http_client_is_chunked_response- 0                                       
_TEST_ esp_http_client_is_chunked_response part_size 4096              
I (8893) ~                       4096 ---> 8023                  
I (8903) Check HEAP ... : free DRAM 32 kB 0x8268 | IRAM 90 kB 0x16814 
I (8913) Check HEAP ... : free DRAM 37 kB 0x9578 | IRAM 94 kB 0x17b24 
*CHECK TASK no: 1074322304       size: 8144

-esp_http_client_is_chunked_response- 0
_TEST_ esp_http_client_is_chunked_response part_size 4096
I (8933) ~                       4096 ---> 12119                 
I (8933) Check HEAP ... : free DRAM 37 kB 0x9634 | IRAM 94 kB 0x17be0 
I (8943) Check HEAP ... : free DRAM 42 kB 0xaa38 | IRAM 99 kB 0x18fe4 

My heap has lost about 90-100kB when perfroming is active and no recover after clanup.
I think this is incorrect.
Next used this metod drop memory to 10kB or lower. Sometimes my wifi componets will crash.

This problem will no show if I didnt use .event_handler = _http_event_handler,
but I need this to operate on HTTP_EVENT_ON_HEADER: and HTTP_EVENT_ON_DATA:

If anyone what could I use incorect? Maybe something in according to connections aspects?

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: http_client componets - function perform and memory problem

Postby ESP_Sprite » Mon Dec 16, 2019 12:45 pm

Are you calling esp_http_client_cleanup() anywhere?

pdemianczuk
Posts: 28
Joined: Thu May 30, 2019 12:05 pm

Re: http_client componets - function perform and memory problem

Postby pdemianczuk » Mon Dec 16, 2019 1:08 pm

Yes, after the call function with esp_http_client_perform

Code: Select all

printf("Client cleanupA ");
   err = esp_http_client_cleanup(client);

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: http_client componets - function perform and memory problem

Postby PeterR » Tue Dec 17, 2019 12:21 am

You need to post more code.
It is not clear why/what you intend by

Code: Select all

if (heap_caps_get_free_size(MALLOC_CAP_8BIT)/1024 > 20)
There is no link between your log and the code i.e. your code (as posted) cannot generate the log. We are therefore at a loss as to your observations!
You say that the problem only happens when you use .

Code: Select all

event_handler = _http_event_handler,
but you have not posted _http_event_handler!
Something in your code is reserving memory but not releasing. If you share that code.....
& I also believe that IDF CAN should be fixed.

pdemianczuk
Posts: 28
Joined: Thu May 30, 2019 12:05 pm

Re: http_client componets - function perform and memory problem

Postby pdemianczuk » Thu Dec 19, 2019 11:53 am

Hi, I probably solve the problem. I update IDF to v4.1-dev-1533 from IDF4.0-dec-667. I had to update also toolchain (to esp-2019r2, compiler to 8.2.0), and I havn't problem with memory.
I found out some https://github.com/espressif/esp-idf/co ... 165cf29087
fix, but I am not sure is this fix the problem.
Generally, You should check is the component is updated.
I dunno know why, my app had a problem but the most people wasnt.

@PeterR
1) I used
if (heap_caps_get_free_size(MALLOC_CAP_8BIT)/1024 > 20)
to don't performing function, to avoid to memory problem, sorry that I didnt write full code, I thoght thats it's not importent, beceasue the problem is visible after first use esp_http_client_perform;
2) sorry for I didnt write full code, but the event_hanlder was like in example from espressif; so I supposed that the problem wasnt there

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 120 guests