Skip to content

Sometimes CURLINFO_PRETRANSFER_TIME_T > CURLINFO_POSTTRANSFER_TIME_T #21828

Description

@BazaarAcc32

I did this

I send a simple GET request. After receiving the response, I print CURLINFO_PRETRANSFER_TIME_T and CURLINFO_POSTTRANSFER_TIME_T, as well as the difference between them. Here is my code:

        CURL* curl = curl_easy_init();
        curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);

        CURLcode res = curl_easy_perform(curl);
        if (res != CURLE_OK) 
        {
            curl_easy_cleanup(curl);
            return 1;
        }

        curl_off_t pretransfer = 0;
        curl_off_t posttransfer = 0;

        curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME_T, &pretransfer);
        curl_easy_getinfo(curl, CURLINFO_POSTTRANSFER_TIME_T, &posttransfer);

        std::cout << "PRETRANSFER_TIME_T: " << pretransfer << " microseconds\n";
        std::cout << "POSTTRANSFER_TIME_T: " << posttransfer << " microseconds\n";
        std::cout << "DIFF: " << (posttransfer - pretransfer) << " microseconds\n";

        curl_easy_cleanup(curl);

I expected the following

I expect that CURLINFO_PRETRANSFER_TIME_T should always be less than CURLINFO_POSTTRANSFER_TIME_T, and the difference between them should always be positive.

However, when sending simple GET requests, I get a CURLINFO_POSTTRANSFER_TIME_T value that is less than the CURLINFO_PRETRANSFER_TIME_T value. How is this possible? This shouldn't happen. Please correct me if I wrong.

Note:
I consider CURLINFO_PRETRANSFER_TIME_T to be the time when libcurl is about to send its first byte to the server, and CURLINFO_POSTTRANSFER_TIME_T to be the time when libcurl sent the last byte to the server. Is my understanding correct?

However, if I send a POST request that sends a file to a remote server, I always get the correct result: CURLINFO_PRETRANSFER_TIME_T < CURLINFO_POSTTRANSFER_TIME_T

curl/libcurl version

libcurl 8.20.0,

operating system

OS: Windows 11, x64
Compiler MSVC (Visual Studio 2022, C++ Project)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions