-
Notifications
You must be signed in to change notification settings - Fork 81
Fix connection leak by request timers not cancelled in time #555
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
Merged
shibd
merged 7 commits into
apache:main
from
BewareMyPower:bewaremypower/fix-pool-close-failure
Mar 19, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ae4386
Fix connection leak by request timers not cancelled in time
BewareMyPower 348b5c2
fix
BewareMyPower 5b0b645
fix include style
BewareMyPower 86e864b
revert consumer stats changes and speed up tests
BewareMyPower 30d27f1
abstract a common method to insert a request and add tests
BewareMyPower 20f971b
remove duplicated emplace
BewareMyPower 6906525
remove unexpected error log
BewareMyPower File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <pulsar/Result.h> | ||
|
|
||
| #include <atomic> | ||
| #include <functional> | ||
| #include <memory> | ||
|
|
||
| #include "AsioDefines.h" | ||
| #include "AsioTimer.h" | ||
| #include "Future.h" | ||
|
|
||
BewareMyPower marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| namespace pulsar { | ||
|
|
||
| template <typename T> | ||
| class PendingRequest : public std::enable_shared_from_this<PendingRequest<T>> { | ||
| public: | ||
| PendingRequest(ASIO::steady_timer timer, std::function<void()> timeoutCallback) | ||
| : timer_(std::move(timer)), timeoutCallback_(std::move(timeoutCallback)) {} | ||
|
|
||
| void initialize() { | ||
| timer_.async_wait([this, weakSelf{this->weak_from_this()}](const auto& error) { | ||
| auto self = weakSelf.lock(); | ||
| if (!self || error || timeoutDisabled_.load(std::memory_order_acquire)) { | ||
| return; | ||
| } | ||
| timeoutCallback_(); | ||
| promise_.setFailed(ResultTimeout); | ||
| }); | ||
| } | ||
|
|
||
| void complete(const T& value) { | ||
| promise_.setValue(value); | ||
| cancelTimer(timer_); | ||
| } | ||
|
|
||
| void fail(Result result) { | ||
| promise_.setFailed(result); | ||
| cancelTimer(timer_); | ||
| } | ||
|
|
||
| void disableTimeout() { timeoutDisabled_.store(true, std::memory_order_release); } | ||
|
|
||
| auto getFuture() const { return promise_.getFuture(); } | ||
|
|
||
| ~PendingRequest() { cancelTimer(timer_); } | ||
|
|
||
| private: | ||
| ASIO::steady_timer timer_; | ||
| Promise<Result, T> promise_; | ||
| std::function<void()> timeoutCallback_; | ||
| std::atomic_bool timeoutDisabled_{false}; | ||
| }; | ||
|
|
||
| template <typename T> | ||
| using PendingRequestPtr = std::shared_ptr<PendingRequest<T>>; | ||
|
|
||
| } // namespace pulsar | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.