Commit f0c238db authored by Scott Pruett's avatar Scott Pruett Committed by Facebook GitHub Bot

fix use-after-scope problems in BoundedAsyncPipeTest

Summary:
BoundedAsyncPipe::write() accepts arguments by-reference, so even
these constants may be out-of-scope by the time the coroutine actually runs,
causing use-after-scope problems which are detected by ASAN.

Wrapping in co_invoke allows us to scope the parameter so that it
lives long enough.

Reviewed By: lxfind

Differential Revision: D26649913

fbshipit-source-id: 5bc6b7f64a5e75c9386b245fa3fd1484efaf1d13
parent 39dba3a0
......@@ -354,7 +354,14 @@ TEST(BoundedAsyncPipeTest, PublisherBlocks) {
co_await pipe.write(i);
}
auto writeFuture = pipe.write(20).scheduleOn(&executor).start();
// wrap in co_invoke() here, since write() accepts arguments by reference,
// and temporaries may go out of scope
auto writeFuture =
folly::coro::co_invoke([&pipe = pipe]() -> folly::coro::Task<bool> {
co_return co_await pipe.write(20);
})
.scheduleOn(&executor)
.start();
executor.drain();
EXPECT_FALSE(writeFuture.isReady());
......@@ -378,7 +385,12 @@ TEST(BoundedAsyncPipeTest, BlockingPublisherCanceledOnDestroy) {
std::vector<folly::SemiFuture<bool>> futures;
for (size_t i = 0; i < 5; ++i) {
auto writeFuture = pipe.write(20).scheduleOn(&executor).start();
auto writeFuture =
folly::coro::co_invoke([&pipe = pipe]() -> folly::coro::Task<bool> {
co_return co_await pipe.write(20);
})
.scheduleOn(&executor)
.start();
executor.drain();
EXPECT_FALSE(writeFuture.isReady());
futures.emplace_back(std::move(writeFuture));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment