-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent TLStatsAsyncAggregator from saving RequestContext to AsyncTim…
…eout Summary: Currently, TLStatsAsyncAggregator::scheduleAggregation will call AsyncTimeout::scheduleTimeout which saves as a default parameter the current RequestContext. The possible issue with this is that RequestContext can possibly persist indefinitely until program end since on the timer expiration, the class calls scheduleTimeout, this cycle will continue. This issue has happened in other areas too, such as HHWheelTimer. Since this class's counters operate on a global scope, it does not make sense to carry any request specific information into the timeout. Thus, for the invocations of scheduleTimeout, we pass in nullptr for the RequestContext. The test case now shows that the RequestContext object is no longer persisted into the timeout. Update: introduced member function scheduleAggregationTimeout to handle the calling of scheduleTimeout. Name helps avoid name clashing with AsyncTimeout and is a bit more descriptive. Reviewed By: ot Differential Revision: D65911229 fbshipit-source-id: 552493f7957425a9a0cfeb2661a53d619871999f
- Loading branch information
1 parent
498cd11
commit eb7069e
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,46 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
#include <fb303/TLStatsAsyncAggregator.h> | ||
#include <folly/io/async/EventBase.h> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace std; | ||
using namespace facebook; | ||
using namespace facebook::fb303; | ||
using namespace folly; | ||
|
||
TEST(TLStatsAsyncAggregatorTest, NoRequestContextLeak) { | ||
// Setup fields | ||
ThreadLocalStatsT<TLStatsNoLocking> tlstats{}; | ||
TLStatsAsyncAggregator aggregator{&tlstats}; | ||
EventBase eventBase; | ||
|
||
// Weak pointer to attach to request context | ||
std::weak_ptr<RequestContext> weakContext; | ||
{ | ||
// Guard to clean up RequestContext in this scope. | ||
RequestContextScopeGuard guard; | ||
weakContext = RequestContext::saveContext(); | ||
aggregator.scheduleAggregation(&eventBase); | ||
} | ||
|
||
// Since we are not carrying request context anymore, | ||
// the RequestContext gets cleared up by guard, | ||
// and no other reference is alive, so nullptr is expected. | ||
EXPECT_TRUE(weakContext.expired()); | ||
} |