Page 1 of 1

http_client componets - function perform and memory problem

Posted: Mon Dec 16, 2019 11:27 am
by pdemianczuk
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?

Re: http_client componets - function perform and memory problem

Posted: Mon Dec 16, 2019 12:45 pm
by ESP_Sprite
Are you calling esp_http_client_cleanup() anywhere?

Re: http_client componets - function perform and memory problem

Posted: Mon Dec 16, 2019 1:08 pm
by pdemianczuk
Yes, after the call function with esp_http_client_perform

Code: Select all

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

Re: http_client componets - function perform and memory problem

Posted: Tue Dec 17, 2019 12:21 am
by PeterR
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.....

Re: http_client componets - function perform and memory problem

Posted: Thu Dec 19, 2019 11:53 am
by pdemianczuk
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