Added request cancellation functionality to the HTTP client.#358
Merged
Conversation
…ied the CurlHttpClient.cpp and Api.cpp files to ensure proper operation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
libcurltimeout to expire.Key Changes
HttpClient.h: Added thecancel()interface and atomic variables (_isEternalCanceland_cancelEpoch) for global management of request cancellation status. Also addedisEternalCancelled()andgetCancelExceptionText()for checking the cancellation status.CurlHttpClient.cpp: Cancellation logic implemented usingCURLOPT_XFERINFOFUNCTION. The progress callback now returns a non-zero value when canceled, instructinglibcurlto safely abort the transfer. The client now emitsstd::runtime_errorcontainingcancelExceptionTextand the name of the aborted request (e.g.request cancelled: getUpdates).Api.cpp: New cancellation capabilities integrated intoApi::sendRequest.