Azat Khuzhin
e8d87053c0
Fix data-race between setConnectionFD() and setTimer() from cancellation path
...
TSan report [1]:
==================
WARNING: ThreadSanitizer: data race (pid=7)
Write of size 8 at 0x7b5000d83768 by thread T539:
0 Poco::Timespan::operator=(Poco::Timespan const&) obj-x86_64-linux-gnu/../contrib/poco/Foundation/src/Timespan.cpp:61:8 (clickhouse+0x18e2da08)
1 DB::RemoteQueryExecutorReadContext::setConnectionFD(int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) obj-x86_64-linux-gnu/../src/DataStreams/RemoteQueryExecutorReadContext.cpp:103:21 (clickhouse+0x142c4f41)
2 DB::RemoteQueryExecutorRoutine::ReadCallback::operator()(int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) obj-x86_64-linux-gnu/../src/DataStreams/RemoteQueryExecutorReadContext.cpp:26:30 (clickhouse+0x142c7dae)
3 decltype(std::__1::forward<DB::RemoteQueryExecutorRoutine::ReadCallback&>(fp)(std::__1::forward<int>(fp0), std::__1::forward<Poco::Timespan>(fp0), std::__1::forward<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(fp0))) std::__1::__invoke<DB::RemoteQueryExecutorRoutine::ReadCallback&, int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(DB::RemoteQueryExecutorRoutine::ReadCallback&, int&&, Poco::Timespan&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) obj-x86_64-linux-gnu/../contrib/libcxx/include/type_traits:3676:1 (clickhouse+0x142c7cf7)
4 void std::__1::__invoke_void_return_wrapper<void>::__call<DB::RemoteQueryExecutorRoutine::ReadCallback&, int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&>(DB::RemoteQueryExecutorRoutine::ReadCallback&, int&&, Poco::Timespan&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) obj-x86_64-linux-gnu/../contrib/libcxx/include/__functional_base:348:9 (clickhouse+0x142c7cf7)
5 std::__1::__function::__default_alloc_func<DB::RemoteQueryExecutorRoutine::ReadCallback, void (int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>::operator()(int&&, Poco::Timespan&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) obj-x86_64-linux-gnu/../contrib/libcxx/include/functional:1608:12 (clickhouse+0x142c7c21)
6 void std::__1::__function::__policy_invoker<void (int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>::__call_impl<std::__1::__function::__default_alloc_func<DB::RemoteQueryExecutorRoutine::ReadCallback, void (int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)> >(std::__1::__function::__policy_storage const*, int, Poco::Timespan&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) obj-x86_64-linux-gnu/../contrib/libcxx/include/functional:2089:16 (clickhouse+0x142c7c21)
7 std::__1::__function::__policy_func<void (int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>::operator()(int&&, Poco::Timespan&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const obj-x86_64-linux-gnu/../contrib/libcxx/include/functional:2221:16 (clickhouse+0x1589a8c1)
8 std::__1::function<void (int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>::operator()(int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const obj-x86_64-linux-gnu/../contrib/libcxx/include/functional:2560:12 (clickhouse+0x1589a8c1)
9 DB::HedgedConnections::getReadyFileDescriptor(std::__1::function<void (int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>) obj-x86_64-linux-gnu/../src/Client/HedgedConnections.cpp:379:13 (clickhouse+0x1589a8c1)
10 DB::HedgedConnections::getReadyReplicaLocation(std::__1::function<void (int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>) obj-x86_64-linux-gnu/../src/Client/HedgedConnections.cpp:317:20 (clickhouse+0x1589a8c1)
11 DB::HedgedConnections::receivePacketUnlocked(std::__1::function<void (int, Poco::Timespan, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>, bool) obj-x86_64-linux-gnu/../src/Client/HedgedConnections.cpp:298:32 (clickhouse+0x1589b531)
12 DB::RemoteQueryExecutorRoutine::operator()(boost::context::fiber&&) const obj-x86_64-linux-gnu/../src/DataStreams/RemoteQueryExecutorReadContext.cpp:46:51 (clickhouse+0x142c7013)
13 std::__1::enable_if<!(std::is_member_pointer<std::__1::decay<DB::RemoteQueryExecutorRoutine&>::type>::value), std::__1::result_of<DB::RemoteQueryExecutorRoutine& (boost::context::fiber&&)>::type>::type boost::context::detail::invoke<DB::RemoteQueryExecutorRoutine&, boost::context::fiber>(DB::RemoteQueryExecutorRoutine&, boost::context::fiber&&) obj-x86_64-linux-gnu/../contrib/boost/boost/context/detail/invoke.hpp:41:12 (clickhouse+0x142c6be1)
14 boost::context::detail::fiber_capture_record<boost::context::fiber, FiberStack&, DB::RemoteQueryExecutorRoutine>::run() obj-x86_64-linux-gnu/../contrib/boost/boost/context/fiber_ucontext.hpp:291:17 (clickhouse+0x142c6be1)
15 void boost::context::detail::fiber_entry_func<boost::context::detail::fiber_capture_record<boost::context::fiber, FiberStack&, DB::RemoteQueryExecutorRoutine> >(void*) obj-x86_64-linux-gnu/../contrib/boost/boost/context/fiber_ucontext.hpp:72:13 (clickhouse+0x142c5f79)
16 <null> <null> (libc.so.6+0x5e65f)
Previous read of size 8 at 0x7b5000d83768 by thread T321 (mutexes: write M861449115349678976, write M1059607378698108960, write M747733173224015304):
0 Poco::Timespan::totalMicroseconds() const obj-x86_64-linux-gnu/../contrib/poco/Foundation/include/Poco/Timespan.h:213:9 (clickhouse+0x142c54b3)
1 DB::RemoteQueryExecutorReadContext::setTimer() const obj-x86_64-linux-gnu/../src/DataStreams/RemoteQueryExecutorReadContext.cpp:160:25 (clickhouse+0x142c54b3)
2 DB::RemoteQueryExecutor::tryCancel(char const*, std::__1::unique_ptr<DB::RemoteQueryExecutorReadContext, std::__1::default_delete<DB::RemoteQueryExecutorReadContext> >*) obj-x86_64-linux-gnu/../src/DataStreams/RemoteQueryExecutor.cpp:538:26 (clickhouse+0x142be3a5)
3 DB::RemoteQueryExecutor::cancel(std::__1::unique_ptr<DB::RemoteQueryExecutorReadContext, std::__1::default_delete<DB::RemoteQueryExecutorReadContext> >*) obj-x86_64-linux-gnu/../src/DataStreams/RemoteQueryExecutor.cpp:462:5 (clickhouse+0x142bdd8a)
4 DB::RemoteSource::onCancel() obj-x86_64-linux-gnu/../src/Processors/Sources/RemoteSource.cpp:112:21 (clickhouse+0x15bf52c6)
5 DB::IProcessor::cancel() obj-x86_64-linux-gnu/../src/Processors/IProcessor.h:237:9 (clickhouse+0x159db37e)
6 DB::PipelineExecutor::cancel() obj-x86_64-linux-gnu/../src/Processors/Executors/PipelineExecutor.cpp:376:20 (clickhouse+0x159db37e)
7 DB::PullingAsyncPipelineExecutor::cancel() obj-x86_64-linux-gnu/../src/Processors/Executors/PullingAsyncPipelineExecutor.cpp:175:25 (clickhouse+0x159e9748)
8 DB::TCPHandler::processOrdinaryQueryWithProcessors() obj-x86_64-linux-gnu/../src/Server/TCPHandler.cpp:700:26 (clickhouse+0x1594f554)
9 DB::TCPHandler::runImpl() obj-x86_64-linux-gnu/../src/Server/TCPHandler.cpp:329:17 (clickhouse+0x15949a2e)
10 DB::TCPHandler::run() obj-x86_64-linux-gnu/../src/Server/TCPHandler.cpp:1658:9 (clickhouse+0x15959007)
11 Poco::Net::TCPServerConnection::start() obj-x86_64-linux-gnu/../contrib/poco/Net/src/TCPServerConnection.cpp:43:3 (clickhouse+0x18cb2e42)
12 Poco::Net::TCPServerDispatcher::run() obj-x86_64-linux-gnu/../contrib/poco/Net/src/TCPServerDispatcher.cpp:115:20 (clickhouse+0x18cb35cf)
13 Poco::PooledThread::run() obj-x86_64-linux-gnu/../contrib/poco/Foundation/src/ThreadPool.cpp:199:14 (clickhouse+0x18e29c21)
14 Poco::(anonymous namespace)::RunnableHolder::run() obj-x86_64-linux-gnu/../contrib/poco/Foundation/src/Thread.cpp:55:11 (clickhouse+0x18e280af)
15 Poco::ThreadImpl::runnableEntry(void*) obj-x86_64-linux-gnu/../contrib/poco/Foundation/src/Thread_POSIX.cpp:345:27 (clickhouse+0x18e26827)
[1]: https://clickhouse-test-reports.s3.yandex.net/27881/b328d9687238617e89c0806c9fa2dd7dd44b5fd7/integration_tests_(thread).htmlfail1
2021-08-25 09:42:30 +03:00