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

SharKCS11
Posts: 2
Joined: Tue Nov 13, 2018 4:18 pm

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

Postby SharKCS11 » 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!

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

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

Postby burkulesomesh43 » Fri Feb 22, 2019 7:42 am

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.
--
Somesh Burkule

guillep2k
Posts: 13
Joined: Tue Feb 12, 2019 8:39 pm

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

Postby guillep2k » 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!

SharKCS11
Posts: 2
Joined: Tue Nov 13, 2018 4:18 pm

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

Postby SharKCS11 » 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!

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

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

Postby burkulesomesh43 » Fri Jun 07, 2019 11:32 am

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.
--
Somesh Burkule

pius4109
Posts: 1
Joined: Sun Aug 29, 2021 12:15 am

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

Postby pius4109 » Sun Aug 29, 2021 12:17 am

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

Who is online

Users browsing this forum: No registered users and 61 guests