Skip to content

Commit

Permalink
rest_client: Improve async() handling in "delayed 200 OK" scenarios
Browse files Browse the repository at this point in the history
In case the 200 OK reply or its body take several seconds to arrive, do
not break the loop prematurely due to a 500ms hardcoded loop timeout and
re-use the configurable "curl_timeout" modparam as loop timeout instead.

(cherry picked from commit 532d8e8)
  • Loading branch information
liviuchircu committed Mar 6, 2023
1 parent 74e2e14 commit ec96e8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions modules/rest_client/rest_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ unsigned int max_transfer_size = 10240; /* KB (10MB) */
* curl_multi_perform() may indicate a "try again" response even
* when resuming transfers with pending data
*/
int _async_resume_retr_timeout = 500000; /* us */
int _async_resume_retr_itv = 100; /* us */
int _async_resume_retr_timeout; /* us; equal to @curl_timeout */
int _async_resume_retr_itv = 500; /* us */

/* libcurl enables these by default */
int ssl_verifypeer = 1;
Expand Down Expand Up @@ -239,6 +239,7 @@ static int mod_init(void)
LM_DBG("Initializing...\n");

connection_timeout_ms = connection_timeout * 1000L;
_async_resume_retr_timeout = curl_timeout * 1000000U;

if (connect_poll_interval < 0) {
LM_ERR("Bad connect_poll_interval (%ldms), setting to 20ms\n",
Expand Down
3 changes: 2 additions & 1 deletion modules/rest_client/rest_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ static enum async_ret_code _resume_async_http_req(int fd, struct sip_msg *msg,
* server body download will be performed within this loop, blocking */

mrc = curl_multi_perform(multi_handle, &running);
LM_DBG("perform result: %d, running: %d\n", mrc, running);
LM_DBG("perform result: %d, running: %d (break: %d)\n", mrc, running,
mrc != CURLM_CALL_MULTI_PERFORM && (mrc != CURLM_OK || !running));

if (mrc != CURLM_CALL_MULTI_PERFORM &&
(mrc != CURLM_OK || !running))
Expand Down

0 comments on commit ec96e8e

Please sign in to comment.