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

Assertion failure in "curl_ws_recv" #10347

StanleyWucw opened this issue Jan 26, 2023 · 3 comments

Assertion failure in "curl_ws_recv" #10347

StanleyWucw opened this issue Jan 26, 2023 · 3 comments


Copy link

I did this

I was trying to receive data from a remote WebSocket server, but I got a debug assertion error.
The code below is running in debug mode in Visual Studio 2022:

        CURL* curl = curl_easy_init();
	curl_easy_setopt(curl, CURLOPT_URL, "wss://");
	curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L);
	// Make a handshake
	bool bOK = CURLE_OK == curl_easy_perform(curl);

	// Send data
	size_t bytes_sent;
	std::string sOut = "{\"message\": \"Hello to libcurl!\"}";
	bOK = CURLE_OK == curl_ws_send(curl, sOut.c_str(), sOut.size(), &bytes_sent, 0, CURLWS_TEXT);

	// Receive data
	size_t rlen;
	struct curl_ws_frame* meta;
	char buffer[256];
	CURLcode result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);


I expected the following

The free WebSocket server "wss://" is an echo server. It sends back whatever it received.

In the above code, the content of the variable "buffer" should be "{"message": "Hello to libcurl!"}" which was returned successfully by the API call "curl_ws_recv." However, that happened only after I closed the pop-up warnings and clicked the "ignore" button. See the image below.


In the release mode of Visual Studio 2022, the above warning pop-up doesn't show.

curl/libcurl version


operating system

Windows 10 with the latest update

Copy link

dfandrich commented Jan 26, 2023 via email

Copy link

Increasing the buffer size doesn't make the assertion failure problem disappear.

I also did the opposite. The meta->bytesleft always returns 0, even if I set the buffer size to be a small number, such as 10. The existing logic of updating the "wsp->frame. bytesleft" inside 'curl_ws_recv' might be flawed.

@bagder bagder self-assigned this Jan 28, 2023
bagder added a commit that referenced this issue Jan 30, 2023
Reported-by: Stanley Wucw
Fixes #10347
Copy link

bagder commented Jan 30, 2023

See #10366 for a possible fix. It makes your test case run fine for me.

@bagder bagder closed this as completed in 0975449 Jan 30, 2023
bch pushed a commit to bch/curl that referenced this issue Jul 19, 2023
Reported-by: Stanley Wucw
Fixes curl#10347
Closes curl#10366
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

No branches or pull requests

3 participants