Skip to content

Added request cancellation functionality to the HTTP client.#358

Merged
reo7sp merged 1 commit into
reo7sp:masterfrom
H-D-OWL:cancel-requests
Jul 13, 2026
Merged

Added request cancellation functionality to the HTTP client.#358
reo7sp merged 1 commit into
reo7sp:masterfrom
H-D-OWL:cancel-requests

Conversation

@H-D-OWL

@H-D-OWL H-D-OWL commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Problem

While working with TgBot::TgLongPoll, I encountered an issue where long-polling and other HTTP requests could not be interrupted gracefully at any time (for example, during a graceful shutdown or during unexpected crashes).

Solution

A mechanism for safely canceling ongoing HTTP requests has been introduced. This allows the bot to immediately abort active network operations without waiting for the libcurl timeout to expire.

Key Changes

  • HttpClient.h: Added the cancel() interface and atomic variables (_isEternalCancel and _cancelEpoch) for global management of request cancellation status. Also added isEternalCancelled() and getCancelExceptionText() for checking the cancellation status.

  • CurlHttpClient.cpp: Cancellation logic implemented using CURLOPT_XFERINFOFUNCTION. The progress callback now returns a non-zero value when canceled, instructing libcurl to safely abort the transfer. The client now emits std::runtime_error containing cancelExceptionText and the name of the aborted request (e.g. request cancelled: getUpdates).

  • Api.cpp: New cancellation capabilities integrated into Api::sendRequest.

…ied the CurlHttpClient.cpp and Api.cpp files to ensure proper operation.

@reo7sp reo7sp left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thank you

@reo7sp reo7sp merged commit a1be2ce into reo7sp:master Jul 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants