Page 1 of 1

How to prevent http request from blocking task for too long?

Posted: Mon Nov 19, 2018 10:54 pm
by SharKCS11
Hi all,
I'm using esp_http_client to make requests to a server. However, when the server is down, the http request is blocking the rest of the task for a very long time.
I want to make it so that if the server is offline and the client can't post, it should immediately stop. Is this possible to do? I tried to change this using the "timeout_ms" parameter in the configuration struct as below:

Code: Select all

esp_http_client_config_t post_config = {
	.url = ip_url,
	.event_handler = post_handler,
	.timeout_ms = 50,
};
post_client = esp_http_client_init(&post_config)
The code to use client just sets the post data and calls

Code: Select all

 esp_http_client_perform(post_client)
as normal.
After this change, the client still attempts the connection for too long. I thought setting ".timeout_ms" would make the client stop blocking after 50ms, but perhaps I misunderstood. Any way to make this happen?
Thanks!

Re: How to prevent http request from blocking task for too long?

Posted: Fri Feb 22, 2019 7:42 am
by burkulesomesh43
SharKCS11 wrote:
Mon Nov 19, 2018 10:54 pm
Hi all,
I'm using esp_http_client to make requests to a server. However, when the server is down, the http request is blocking the rest of the task for a very long time.
I want to make it so that if the server is offline and the client can't post, it should immediately stop. Is this possible to do? I tried to change this using the "timeout_ms" parameter in the configuration struct as below:

Code: Select all

esp_http_client_config_t post_config = {
	.url = ip_url,
	.event_handler = post_handler,
	.timeout_ms = 50,
};
post_client = esp_http_client_init(&post_config)
The code to use client just sets the post data and calls

Code: Select all

 esp_http_client_perform(post_client)
as normal.
After this change, the client still attempts the connection for too long. I thought setting ".timeout_ms" would make the client stop blocking after 50ms, but perhaps I misunderstood. Any way to make this happen?
Thanks!
Heyy.. Is this issue resolved??
I am also have same issue. esp_http_client_perform blocking the task.
Not getting any solution. also no response from forum for this issue.
Please let me know as early as possible.

Re: How to prevent http request from blocking task for too long?

Posted: Fri Feb 22, 2019 11:58 pm
by guillep2k
Have you tried using a separate FreeRTOS task for the request? Check the xTaskCreate() function, and use semaphores to coordinate the tasks. YouTube is your friend!

Re: How to prevent http request from blocking task for too long?

Posted: Sat Feb 23, 2019 9:06 pm
by SharKCS11
The issue was never resolved. I had to try HTTP posting to the server, and if it failed twice, then I just deemed the server dead for the remainder of the application's lifetime.
Not ideal at all, but was good enough for my purpose. I hope it gets resolved!

Re: How to prevent http request from blocking task for too long?

Posted: Fri Jun 07, 2019 11:32 am
by burkulesomesh43
SharKCS11 wrote:
Sat Feb 23, 2019 9:06 pm
The issue was never resolved. I had to try HTTP posting to the server, and if it failed twice, then I just deemed the server dead for the remainder of the application's lifetime.
Not ideal at all, but was good enough for my purpose. I hope it gets resolved!
I am using watchdog.
if request is blocked for more than 60seconds, I am reseting esp.

Re: How to prevent http request from blocking task for too long?

Posted: Sun Aug 29, 2021 12:17 am
by pius4109
guillep2k wrote:
Fri Feb 22, 2019 11:58 pm
Have you tried using a separate FreeRTOS task for the request? Check the xTaskCreate() function, and use semaphores to coordinate the tasks. YouTube is your friend!
I tried this but the request kept failing