jiridanek commented on a change in pull request #309: URL: https://github.com/apache/qpid-proton/pull/309#discussion_r615581743
########## File path: cpp/src/delivery_test.cpp ########## @@ -0,0 +1,132 @@ +/* + * + * 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. + * + */ + +#include <proton/connection.hpp> +#include <proton/connection_options.hpp> +#include <proton/container.hpp> +#include <proton/delivery.h> +#include <proton/delivery.hpp> +#include <proton/link.hpp> +#include <proton/listen_handler.hpp> +#include <proton/listener.hpp> +#include <proton/message.hpp> +#include <proton/message_id.hpp> +#include <proton/messaging_handler.hpp> +#include <proton/tracker.hpp> +#include <proton/types.h> +#include <proton/types.hpp> +#include <proton/value.hpp> + +#include "proton/error_condition.hpp" +#include "proton/internal/pn_unique_ptr.hpp" +#include "proton/receiver_options.hpp" +#include "proton/transport.hpp" +#include "proton/work_queue.hpp" +#include "test_bits.hpp" + +#include <condition_variable> +#include <mutex> +#include <thread> + +namespace { +std::mutex m; +std::condition_variable cv; +bool listener_ready = false; +int listener_port; +} // namespace + +class test_recv : public proton::messaging_handler { + private: + class listener_ready_handler : public proton::listen_handler { + void on_open(proton::listener &l) PN_CPP_OVERRIDE { + std::cout << "listening on " << l.port() << std::endl; + listener_port = l.port(); + listener_ready = true; Review comment: https://travis-ci.com/github/apache/qpid-proton/jobs/499340056#L5205 ``` 23: Test command: /opt/pyenv/shims/python3 "/home/travis/build/apache/qpid-proton/scripts/env.py" "--" "TSAN_OPTIONS=second_deadlock_stack=1 suppressions=/home/travis/build/apache/qpid-proton/tests/tsan.supp" "PN_SASL_CONFIG_PATH=/home/travis/build/apache/qpid-proton/build/cpp/testdata/sasl-conf" "/home/travis/build/apache/qpid-proton/build/cpp/delivery_test" 23: Test timeout computed to be: 360 23: TEST: test_delivery_tag() 23: listening on 43505 23: ================== 23: WARNING: ThreadSanitizer: data race (pid=14832) 23: Write of size 1 at 0x555ab72fc164 by thread T1: 23: #0 test_recv::listener_ready_handler::on_open(proton::listener&) /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:62 (delivery_test+0x7fee) 23: #1 proton::container::impl::dispatch(pn_event_t*) /home/travis/build/apache/qpid-proton/cpp/src/proactor_container_impl.cpp:602 (libqpid-proton-cpp.so.12+0x4d02d) 23: #2 proton::container::impl::thread() /home/travis/build/apache/qpid-proton/cpp/src/proactor_container_impl.cpp:765 (libqpid-proton-cpp.so.12+0x4d567) 23: #3 proton::container::impl::run(int) /home/travis/build/apache/qpid-proton/cpp/src/proactor_container_impl.cpp:812 (libqpid-proton-cpp.so.12+0x4db6b) 23: #4 proton::container::run() /home/travis/build/apache/qpid-proton/cpp/src/container.cpp:92 (libqpid-proton-cpp.so.12+0x3587b) 23: #5 operator() /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:113 (delivery_test+0x6628) 23: #6 __invoke_impl<void, test_delivery_tag()::<lambda()> > /usr/include/c++/10/bits/invoke.h:60 (delivery_test+0x6628) 23: #7 __invoke<test_delivery_tag()::<lambda()> > /usr/include/c++/10/bits/invoke.h:95 (delivery_test+0x6628) 23: #8 _M_invoke<0> /usr/include/c++/10/thread:264 (delivery_test+0x6628) 23: #9 operator() /usr/include/c++/10/thread:271 (delivery_test+0x6628) 23: #10 _M_run /usr/include/c++/10/thread:215 (delivery_test+0x6628) 23: #11 <null> <null> (libstdc++.so.6+0xd6d83) 23: 23: Previous read of size 1 at 0x555ab72fc164 by main thread (mutexes: write M50): 23: #0 operator() /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:117 (delivery_test+0x6c14) 23: #1 wait<test_delivery_tag()::<lambda()> > /usr/include/c++/10/condition_variable:110 (delivery_test+0x6c14) 23: #2 test_delivery_tag() /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:117 (delivery_test+0x6c14) 23: #3 main /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:130 (delivery_test+0x646c) 23: 23: Location is global '(anonymous namespace)::listener_ready' of size 1 at 0x555ab72fc164 (delivery_test+0x00000000c164) 23: 23: Mutex M50 (0x555ab72fc1c0) created at: 23: #0 pthread_mutex_lock <null> (libtsan.so.0+0x5271c) 23: #1 __gthread_mutex_lock /usr/include/x86_64-linux-gnu/c++/10/bits/gthr-default.h:749 (delivery_test+0x6be6) 23: #2 std::mutex::lock() /usr/include/c++/10/bits/std_mutex.h:100 (delivery_test+0x6be6) 23: #3 std::unique_lock<std::mutex>::lock() /usr/include/c++/10/bits/unique_lock.h:138 (delivery_test+0x6be6) 23: #4 std::unique_lock<std::mutex>::unique_lock(std::mutex&) /usr/include/c++/10/bits/unique_lock.h:68 (delivery_test+0x6be6) 23: #5 test_delivery_tag() /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:116 (delivery_test+0x6be6) 23: #6 main /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:130 (delivery_test+0x646c) 23: 23: Thread T1 (tid=14834, running) created by main thread at: 23: #0 pthread_create <null> (libtsan.so.0+0x5ea99) 23: #1 std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) <null> (libstdc++.so.6+0xd7048) 23: #2 main /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:130 (delivery_test+0x646c) 23: 23: SUMMARY: ThreadSanitizer: data race /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:62 in test_recv::listener_ready_handler::on_open(proton::listener&) 23: ================== 23: ================== 23: WARNING: ThreadSanitizer: data race (pid=14832) 23: Read of size 4 at 0x555ab72fc160 by main thread (mutexes: write M50): 23: #0 test_delivery_tag() /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:120 (delivery_test+0x6c4b) 23: #1 main /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:130 (delivery_test+0x646c) 23: 23: Previous write of size 4 at 0x555ab72fc160 by thread T1: 23: #0 test_recv::listener_ready_handler::on_open(proton::listener&) /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:61 (delivery_test+0x7fdb) 23: #1 proton::container::impl::dispatch(pn_event_t*) /home/travis/build/apache/qpid-proton/cpp/src/proactor_container_impl.cpp:602 (libqpid-proton-cpp.so.12+0x4d02d) 23: #2 proton::container::impl::thread() /home/travis/build/apache/qpid-proton/cpp/src/proactor_container_impl.cpp:765 (libqpid-proton-cpp.so.12+0x4d567) 23: #3 proton::container::impl::run(int) /home/travis/build/apache/qpid-proton/cpp/src/proactor_container_impl.cpp:812 (libqpid-proton-cpp.so.12+0x4db6b) 23: #4 proton::container::run() /home/travis/build/apache/qpid-proton/cpp/src/container.cpp:92 (libqpid-proton-cpp.so.12+0x3587b) 23: #5 operator() /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:113 (delivery_test+0x6628) 23: #6 __invoke_impl<void, test_delivery_tag()::<lambda()> > /usr/include/c++/10/bits/invoke.h:60 (delivery_test+0x6628) 23: #7 __invoke<test_delivery_tag()::<lambda()> > /usr/include/c++/10/bits/invoke.h:95 (delivery_test+0x6628) 23: #8 _M_invoke<0> /usr/include/c++/10/thread:264 (delivery_test+0x6628) 23: #9 operator() /usr/include/c++/10/thread:271 (delivery_test+0x6628) 23: #10 _M_run /usr/include/c++/10/thread:215 (delivery_test+0x6628) 23: #11 <null> <null> (libstdc++.so.6+0xd6d83) 23: 23: Location is global '(anonymous namespace)::listener_port' of size 4 at 0x555ab72fc160 (delivery_test+0x00000000c160) 23: 23: Mutex M50 (0x555ab72fc1c0) created at: 23: #0 pthread_mutex_lock <null> (libtsan.so.0+0x5271c) 23: #1 __gthread_mutex_lock /usr/include/x86_64-linux-gnu/c++/10/bits/gthr-default.h:749 (delivery_test+0x6be6) 23: #2 std::mutex::lock() /usr/include/c++/10/bits/std_mutex.h:100 (delivery_test+0x6be6) 23: #3 std::unique_lock<std::mutex>::lock() /usr/include/c++/10/bits/unique_lock.h:138 (delivery_test+0x6be6) 23: #4 std::unique_lock<std::mutex>::unique_lock(std::mutex&) /usr/include/c++/10/bits/unique_lock.h:68 (delivery_test+0x6be6) 23: #5 test_delivery_tag() /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:116 (delivery_test+0x6be6) 23: #6 main /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:130 (delivery_test+0x646c) 23: 23: Thread T1 (tid=14834, running) created by main thread at: 23: #0 pthread_create <null> (libtsan.so.0+0x5ea99) 23: #1 std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) <null> (libstdc++.so.6+0xd7048) 23: #2 main /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:130 (delivery_test+0x646c) 23: 23: SUMMARY: ThreadSanitizer: data race /home/travis/build/apache/qpid-proton/cpp/src/delivery_test.cpp:120 in test_delivery_tag() 23: ================== 23: ThreadSanitizer: reported 2 warnings 23/46 Test #23: cpp-delivery_test ................***Failed 0.15 sec ``` CI caught something about this that it does not like. Do you see what's wrong/different from the cppreference.com usage example :P ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org For additional commands, e-mail: dev-h...@qpid.apache.org