Skip to content
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

UNSUPPORTED_PROTOCOL from curl_easy_send on handle removed from curl_multi #9244

Closed
redbaron opened this issue Aug 3, 2022 · 3 comments
Closed

Comments

@redbaron
Copy link

redbaron commented Aug 3, 2022

I did this

If CURLOPT_CONNECT_ONLY socket was connected using mutli interface, then curl_easy_send returns CURLE_UNSUPPORTED_PROTOCOL. Here is minimal reproducer.

main.cpp:

#include <curl/curl.h>
#include <cassert>


int main(int, char**) {
    CURL* e = curl_easy_init();
    curl_easy_setopt(e, CURLOPT_URL, "http://google.com/");
    curl_easy_setopt(e, CURLOPT_CONNECT_ONLY, 1);
    curl_easy_setopt(e, CURLOPT_VERBOSE, 1);

    CURLM* m = curl_multi_init();
    curl_multi_add_handle(m, e);

    int count;
    do {
        curl_multi_perform(m, &count);
    } while (count > 0);

    CURLMsg* msg = curl_multi_info_read(m, &count);
    assert(msg);
    assert(count == 0);
    assert(msg->easy_handle == e);
    assert(msg->data.result == CURLE_OK);

    curl_multi_remove_handle(m, e);

    const char buf[] = "XYZ";
    size_t sent;
    CURLcode res = curl_easy_send(e, buf, sizeof(buf), &sent);
    assert(res == CURLE_OK); // CURLE_UNSUPPORTED_PROTOCOL is returned

    curl_easy_cleanup(e);
    curl_multi_cleanup(m);
    return 0;
}

I expected the following

curl_easy_send is usable after curl_multi_remove_handle returns;

curl/libcurl version

7.84.0

operating system

Linux WSL2

@redbaron
Copy link
Author

redbaron commented Aug 3, 2022

Hm, commenting curl_multi_remove_handle call makes it work. Reading curl_multi_add_handle doc I was under impression that I shouldn't call any curl_easy_* IO functions until handle is removed from multi, even though docs talks about curl_easy_perform only.

I am not sure if not calling curl_multi_remove_handle is an intended use of CURLOPT_CONNECT_ONLY sockets or just a workaround sidestepping legitimate bug.

@bagder
Copy link
Member

bagder commented Aug 4, 2022

I think this is mostly a case where we should update/clarify the documentation.

bagder added a commit that referenced this issue Aug 6, 2022
Reported-by: Maxim Ivanov
Fixes #9244
Closes #
@bagder
Copy link
Member

bagder commented Aug 6, 2022

#9262 is my attempt to clarify how to use this feature with the multi interface

@bagder bagder closed this as completed in ba670b3 Aug 7, 2022
vszakats added a commit to vszakats/curl that referenced this issue Oct 11, 2022
PR curl#9244 aimed to fix a Cygwin/MSYS issue. It used the `CURL_WIN32`
macro, but that one is never defined while compiling curl itself. This
patch changes this to `WIN32`, assuming this was the original intent.

Regression from 1c52e8a.

Ref: curl#8220
Ref: curl#9255

Closes #xxxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants