Thanks to visit codestin.com
Credit goes to github.com

Skip to content

multi: support mark conncache as stale when network change #17246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Cering
Copy link
Contributor

@Cering Cering commented May 3, 2025

this PR is a simple solution for #17225

@bagder bagder added the feature-window A merge of this requires an open feature window label May 3, 2025
@bagder
Copy link
Member

bagder commented May 3, 2025

Thanks! Here are some good next steps:

  1. Update docs/libcurl/symbols-in-version
  2. Provide at least one test case that shows the feature working
  3. Add documentation so that we can verify that the code seems to work as documented and vice versa

@testclutch
Copy link

Analysis of PR #17246 at 3db12794:

Test 1119 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 540 different CI jobs (the link just goes to one of them).

Test 284 failed, which has NOT been flaky recently, so there could be a real issue in this PR.

Test 2301 failed, which has NOT been flaky recently, so there could be a real issue in this PR.

Test 2302 failed, which has NOT been flaky recently, so there could be a real issue in this PR.

Test 2101 failed, which has NOT been flaky recently, so there could be a real issue in this PR.

Test 987 failed, which has NOT been flaky recently, so there could be a real issue in this PR.

Test 988 failed, which has NOT been flaky recently, so there could be a real issue in this PR.

There are more failures, but that's enough from Gha.

Generated by Testclutch

@Cering
Copy link
Contributor Author

Cering commented May 7, 2025

  1. Update docs/libcurl/symbols-in-version
  • Done
  1. Provide at least one test case that shows the feature working
  • a litte difficulty for me to write a standard unit test, is it ok to provide a c demo code like below?
#include <unistd.h>
#include "curl/curl.h"

int mycurl_debug(CURL *handle, curl_infotype type, char *data,
                 size_t size, void *userptr)
{
    if(type == CURLINFO_TEXT)
        printf("mycurl_debug[%d]: %s\n", type, data);
    return 0;
}

int main(void)
{
    CURLM *multi_handle;
    CURL *easy_handle;
    CURLMsg *msg;
    const int try_times = 3;
    const char *url = "https://www.example.com/";

    curl_global_init(CURL_GLOBAL_ALL);
    printf("%s\n", curl_version());

    multi_handle = curl_multi_init();

    for(int req_id = 0; req_id < try_times; req_id++) {
        printf("New Request[%d]: %s\n", req_id, url);
        int still_running = 0;
        easy_handle = curl_easy_init();
        curl_easy_setopt(easy_handle, CURLOPT_URL, url);
        curl_easy_setopt(easy_handle, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(easy_handle, CURLOPT_DEBUGFUNCTION, mycurl_debug);
        curl_multi_add_handle(multi_handle, easy_handle);

        if(req_id == 1) {
            curl_multi_setopt(multi_handle, CURLMOPT_CONNCACHE_STALE, 1L);
            printf("Set CURLMOPT_CONNCACHE_STALE=1 before request[%d]\n", req_id);
        }
        else if(req_id == 2) {
            curl_multi_setopt(multi_handle, CURLMOPT_CONNCACHE_STALE, 0L);
            printf("Set CURLMOPT_CONNCACHE_STALE=0 before request[%d]\n", req_id);
        }

        do {
            int numfds = 0;
            curl_multi_perform(multi_handle, &still_running);
            curl_multi_wait(multi_handle, NULL, 0, 10, &numfds);
        } while(still_running);

        do {
            long num_connects = 0L;
            CURLcode code;
            msg = curl_multi_info_read(multi_handle, &still_running);
            if(!msg)
                break;
            if(msg->msg != CURLMSG_DONE)
                continue;

            curl_easy_getinfo(easy_handle, CURLINFO_NUM_CONNECTS,
                              &num_connects);
            code = msg->data.result;
            curl_multi_remove_handle(multi_handle, easy_handle);
            printf("Request[%d] result %ld, num connects %ld\n",
                   req_id, code, num_connects);
        } while(msg);

        curl_easy_cleanup(easy_handle);
        sleep(1);
    }

    curl_multi_cleanup(multi_handle);
    return 0;
}
  • the major test log are like:
    • Request[0] create a new connection and left in pool

    New Request[0]: https://www.example.com/
    mycurl_debug[0]: Connection #0 to host www.example.com left intact
    Request[0] result 0, num connects 1

    • Request[1] set pool's connections stale and not reuse, create another connection

    New Request[1]: https://www.example.com/
    Set CURLMOPT_CONNCACHE_STALE=1 before request[1]
    mycurl_debug[0]: Connection #0 is stale for 4927 ms, cannot reuse
    mycurl_debug[0]: Connection # 1 to host www.example.com left intact
    Request[1] result 0, num connects 1

    • Request[2] disabled pool's connections stale option, and reused the Request[0]'s connection

    New Request[2]: https://www.example.com/
    Set CURLMOPT_CONNCACHE_STALE=0 before request[2]
    mycurl_debug[0]: Re-using existing https: connection with host www.example.com
    mycurl_debug[0]: Connection #0 to host www.example.com left intact
    Request[2] result 0, num connects 0

  1. Add documentation so that we can verify that the code seems to work as documented and vice versa
  • Done

@Cering Cering force-pushed the dev branch 3 times, most recently from de7d76c to 251a3c6 Compare May 8, 2025 14:06
@github-actions github-actions bot added the tests label May 8, 2025
@Cering Cering force-pushed the dev branch 5 times, most recently from 0572163 to c39c8d3 Compare May 8, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-window A merge of this requires an open feature window libcurl API tests
Development

Successfully merging this pull request may close these issues.

3 participants