Skip to content
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

[YSQL] Undefined behavior around PerformFuture in PG backend shutdown #12490

Closed
bmatican opened this issue May 12, 2022 · 0 comments
Closed

[YSQL] Undefined behavior around PerformFuture in PG backend shutdown #12490

bmatican opened this issue May 12, 2022 · 0 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@bmatican
Copy link
Contributor

bmatican commented May 12, 2022

Jira Link: [DB-323](https://yugabyte.atlassian.net/browse/DB-323)

Description

/opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/future:1116:17: runtime error: member call on null pointer of type 'std::__assoc_state<yb::pggate::PerformResult>'
    #0 0x7fe559480317 in std::__1::future<yb::pggate::PerformResult>::get() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/future:1116:17
    #1 0x7fe55947fdf0 in yb::pggate::PerformFuture::Get() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_perform_future.cc:40:25
    #2 0x7fe5594faf3d in yb::pggate::PgDocOp::~PgDocOp() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_doc_op.cc:212:5
    #3 0x7fe55950b866 in yb::pggate::PgDocReadOp::~PgDocReadOp() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_doc_op.h:413:7
    #4 0x7fe55941418b in void std::__1::destroy_at<yb::pggate::PgDocReadOp>(yb::pggate::PgDocReadOp*) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/__memory/base.h:118:13
    #5 0x7fe559414143 in void std::__1::allocator_traits<std::__1::allocator<yb::pggate::PgDocReadOp> >::destroy<yb::pggate::PgDocReadOp, void, void>(std::__1::allocator<yb::pggate::PgDocReadOp>&, yb::pggate::PgDocReadOp*) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/__memory/allocator_traits.h:315:9
    #6 0x7fe559413f39 in std::__1::__shared_ptr_emplace<yb::pggate::PgDocReadOp, std::__1::allocator<yb::pggate::PgDocReadOp> >::__on_zero_shared() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/memory:2637:9
    #7 0x7fe5593d3397 in std::__1::__shared_count::__release_shared() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/memory:2501:9
    #8 0x7fe5593d332d in std::__1::__shared_weak_count::__release_shared() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/memory:2543:27
    #9 0x7fe559409804 in std::__1::shared_ptr<yb::pggate::PgDocOp>::~shared_ptr() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/memory:3233:19
    #10 0x7fe5594b41d2 in yb::pggate::PgDml::~PgDml() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_dml.cc:63:1
    #11 0x7fe5594d0336 in yb::pggate::PgDmlRead::~PgDmlRead() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_dml_read.cc:104:1
    #12 0x7fe5594e18f8 in yb::pggate::PgSelect::~PgSelect() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_select.cc:37:1
    #13 0x7fe5594e190d in yb::pggate::PgSelect::~PgSelect() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_select.cc:36:23
    #14 0x7fe559541a54 in std::__1::default_delete<yb::pggate::PgMemctx::Registrable>::operator()(yb::pggate::PgMemctx::Registrable*) const /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/memory:1423:5
    #15 0x7fe55953a8c8 in void boost::intrusive::list_impl<boost::intrusive::bhtraits<yb::pggate::PgMemctx::Registrable, boost::intrusive::list_node_traits<void*>, (boost::intrusive::link_mode_type)1, boost::intrusive::dft_tag, 1u>, unsigned long, true, void>::clear_and_dispose<std::__1::default_delete<yb::pggate::PgMemctx::Registrable> >(std::__1::default_delete<yb::pggate::PgMemctx::Registrable>) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/include/boost/intrusive/list.hpp:756:10
    #16 0x7fe559538a1d in yb::pggate::PgMemctx::Clear() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_memctx.cc:80:23
    #17 0x7fe5595389ce in yb::pggate::PgMemctx::~PgMemctx() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_memctx.cc:29:3
    #18 0x7fe55953e0fb in void std::__1::destroy_at<yb::pggate::PgMemctx>(yb::pggate::PgMemctx*) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/__memory/base.h:118:13
    #19 0x7fe55953e0b3 in void std::__1::allocator_traits<std::__1::allocator<yb::pggate::PgMemctx> >::destroy<yb::pggate::PgMemctx, void, void>(std::__1::allocator<yb::pggate::PgMemctx>&, yb::pggate::PgMemctx*) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/__memory/allocator_traits.h:315:9
    #20 0x7fe55953de99 in std::__1::__shared_ptr_emplace<yb::pggate::PgMemctx, std::__1::allocator<yb::pggate::PgMemctx> >::__on_zero_shared() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/memory:2637:9
    #21 0x7fe5593d3397 in std::__1::__shared_count::__release_shared() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/memory:2501:9
    #22 0x7fe5593d332d in std::__1::__shared_weak_count::__release_shared() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/memory:2543:27
    #23 0x7fe559539f84 in std::__1::shared_ptr<yb::pggate::PgMemctx>::~shared_ptr() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/memory:3233:19
    #24 0x7fe55953d46c in std::__1::pair<yb::pggate::PgMemctx* const, std::__1::shared_ptr<yb::pggate::PgMemctx> >::~pair() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/utility:297:29
    #25 0x7fe55953d44b in void std::__1::destroy_at<std::__1::pair<yb::pggate::PgMemctx* const, std::__1::shared_ptr<yb::pggate::PgMemctx> > >(std::__1::pair<yb::pggate::PgMemctx* const, std::__1::shared_ptr<yb::pggate::PgMemctx> >*) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/__memory/base.h:118:13
    #26 0x7fe55953d383 in void std::__1::allocator_traits<std::__1::allocator<std::__1::__hash_node<std::__1::__hash_value_type<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx> >, void*> > >::destroy<std::__1::pair<yb::pggate::PgMemctx* const, std::__1::shared_ptr<yb::pggate::PgMemctx> >, void, void>(std::__1::allocator<std::__1::__hash_node<std::__1::__hash_value_type<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx> >, void*> >&, std::__1::pair<yb::pggate::PgMemctx* const, std::__1::shared_ptr<yb::pggate::PgMemctx> >*) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/__memory/allocator_traits.h:315:9
    #27 0x7fe55953d2e9 in std::__1::__hash_table<std::__1::__hash_value_type<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx> >, std::__1::__unordered_map_hasher<yb::pggate::PgMemctx*, std::__1::__hash_value_type<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx> >, std::__1::hash<yb::pggate::PgMemctx*>, std::__1::equal_to<yb::pggate::PgMemctx*>, true>, std::__1::__unordered_map_equal<yb::pggate::PgMemctx*, std::__1::__hash_value_type<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx> >, std::__1::equal_to<yb::pggate::PgMemctx*>, std::__1::hash<yb::pggate::PgMemctx*>, true>, std::__1::allocator<std::__1::__hash_value_type<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx> > > >::__deallocate_node(std::__1::__hash_node_base<std::__1::__hash_node<std::__1::__hash_value_type<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx> >, void*>*>*) /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/__hash_table:1580:9
    #28 0x7fe5595447aa in std::__1::__hash_table<std::__1::__hash_value_type<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx> >, std::__1::__unordered_map_hasher<yb::pggate::PgMemctx*, std::__1::__hash_value_type<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx> >, std::__1::hash<yb::pggate::PgMemctx*>, std::__1::equal_to<yb::pggate::PgMemctx*>, true>, std::__1::__unordered_map_equal<yb::pggate::PgMemctx*, std::__1::__hash_value_type<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx> >, std::__1::equal_to<yb::pggate::PgMemctx*>, std::__1::hash<yb::pggate::PgMemctx*>, true>, std::__1::allocator<std::__1::__hash_value_type<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx> > > >::clear() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/__hash_table:1826:9
    #29 0x7fe55953ae18 in std::__1::unordered_map<yb::pggate::PgMemctx*, std::__1::shared_ptr<yb::pggate::PgMemctx>, std::__1::hash<yb::pggate::PgMemctx*>, std::__1::equal_to<yb::pggate::PgMemctx*>, std::__1::allocator<std::__1::pair<yb::pggate::PgMemctx* const, std::__1::shared_ptr<yb::pggate::PgMemctx> > > >::clear() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/unordered_map:1274:42
    #30 0x7fe559539917 in yb::pggate::ClearGlobalPgMemctxMap() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_memctx.cc:99:28
    #31 0x7fe5593aea98 in YBCDestroyPgGate /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/ybc_pggate.cc:144:5
    #32 0x1869fba in YBOnPostgresBackendShutdown /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/utils/misc/../../../../../../../src/postgres/src/backend/utils/misc/pg_yb_utils.c:548:2
    #33 0x1418c12 in quickdie /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/tcop/../../../../../../src/postgres/src/backend/tcop/postgres.c:2696:3
    #34 0x7fe55800bc1f  (/lib64/libpthread.so.0+0x12c1f)
    #35 0x7fe5580073f9 in pthread_cond_wait@@GLIBC_2.3.2 (/lib64/libpthread.so.0+0xe3f9)
    #36 0x7fe55cc83e2a in std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) (/opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/lib/libc++.so.1+0x1dde2a)
    #37 0x7fe55cc86f1e in std::__1::__assoc_sub_state::__sub_wait(std::__1::unique_lock<std::__1::mutex>&) (/opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/lib/libc++.so.1+0x1e0f1e)
    #38 0x7fe55948277e in std::__1::__assoc_state<yb::pggate::PerformResult>::move() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/future:678:11
    #39 0x7fe5594802b4 in std::__1::future<yb::pggate::PerformResult>::get() /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/future:1116:17
    #40 0x7fe55947fdf0 in yb::pggate::PerformFuture::Get() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_perform_future.cc:40:25
    #41 0x7fe5594fba86 in yb::pggate::PgDocOp::GetResult(std::__1::list<yb::pggate::PgDocResult, std::__1::allocator<yb::pggate::PgDocResult> >*) /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_doc_op.cc:253:29
    #42 0x7fe5594b8972 in yb::pggate::PgDml::FetchDataFromServer() /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_dml.cc:376:3
    #43 0x7fe5594b7c9a in yb::pggate::PgDml::Fetch(int, unsigned long*, bool*, PgSysColumns*, bool*) /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pg_dml.cc:364:10
    #44 0x7fe5593f1947 in yb::pggate::PgApiImpl::DmlFetch(yb::pggate::PgStatement*, int, unsigned long*, bool*, PgSysColumns*, bool*) /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/pggate.cc:1007:37
    #45 0x7fe5593b64fa in YBCPgDmlFetch /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/../../src/yb/yql/pggate/ybc_pggate.cc:657:29
    #46 0xb98787 in YbGetMasterCatalogVersionFromTable /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/catalog/yb_catalog/../../../../../../../src/postgres/src/backend/catalog/yb_catalog/yb_catalog_version.c:299:17
    #47 0xb9826b in YbGetMasterCatalogVersion /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/catalog/yb_catalog/../../../../../../../src/postgres/src/backend/catalog/yb_catalog/yb_catalog_version.c:55:8
    #48 0x1423171 in YBRefreshCache /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/tcop/../../../../../../src/postgres/src/backend/tcop/postgres.c:3729:42
    #49 0x14248d4 in YBCheckSharedCatalogCacheVersion /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/tcop/../../../../../../src/postgres/src/backend/tcop/postgres.c:4041:3
    #50 0x141c116 in PostgresMain /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/tcop/../../../../../../src/postgres/src/backend/tcop/postgres.c:5193:4
    #51 0x126bd9c in BackendRun /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/postmaster/../../../../../../src/postgres/src/backend/postmaster/postmaster.c:4555:2
    #52 0x126ac46 in BackendStartup /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/postmaster/../../../../../../src/postgres/src/backend/postmaster/postmaster.c:4198:3
    #53 0x1268753 in ServerLoop /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/postmaster/../../../../../../src/postgres/src/backend/postmaster/postmaster.c:1767:7
    #54 0x1264a98 in PostmasterMain /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/postmaster/../../../../../../src/postgres/src/backend/postmaster/postmaster.c:1423:11
    #55 0x10568f9 in PostgresServerProcessMain /nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/src/postgres/src/backend/main/../../../../../../src/postgres/src/backend/main/main.c:234:3
    #56 0x1056de1 in main (/nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/postgres/bin/postgres+0x1056de1)
    #57 0x7fe557c57492 in __libc_start_main (/lib64/libc.so.6+0x23492)
    #58 0x8be3fd in _start (/nfusr/alma8-gcp-cloud/jenkins-worker-lkq9iq/jenkins/jenkins-github-yugabyte-db-alma8-master-clang12-asan-422/build/asan-clang12-dynamic-ninja/postgres/bin/postgres+0x8be3fd)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20220505181611-c1907426fc-almalinux8-x86_64-clang12/installed/asan/libcxx/include/c++/v1/future:1116:17 in 

Examples
https://jenkins.dev.yugabyte.com/job/github-yugabyte-db-alma8-master-clang12-asan/422/artifact/build/asan-clang12-dynamic-ninja/yb-test-logs/tests-pgwrapper__pg_catalog_perf-test/PgCatalogPerfTest_CacheRefreshRPCCountWithPartitionTables.log
https://jenkins.dev.yugabyte.com/job/github-yugabyte-db-alma8-master-clang12-asan/422/artifact/build/asan-clang12-dynamic-ninja/yb-test-logs/tests-pgwrapper__pg_fkey-test/PgFKeyTest_AddFKCorrectnessOnTempTables.log
https://jenkins.dev.yugabyte.com/job/github-yugabyte-db-alma8-master-clang12-asan/422/artifact/build/asan-clang12-dynamic-ninja/yb-test-logs/tests-pgwrapper__alter_table_with_concurrent_txn-test/AlterTableWithConcurrentTxnTest_TServerLeaderChange.log
https://jenkins.dev.yugabyte.com/job/github-yugabyte-db-alma8-master-clang12-asan/422/artifact/build/asan-clang12-dynamic-ninja/yb-test-logs/tests-pgwrapper__pg_mini-test/PgMiniTest_BigInsertWithRestart.log

cc @spolitov

@bmatican bmatican added area/ysql Yugabyte SQL (YSQL) kind/failing-test Tests and testing infra labels May 12, 2022
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels May 12, 2022
d-uspenskiy added a commit that referenced this issue Jun 3, 2022
…utdown

Summary:
The diff consists of 3 parts.

**Part #1:** Multiple call of the `PerformFuture::Get` method
In case of session close when temp tables exists the following stack is possible

```
std::__1::future<yb::pggate::PerformResult>::get()
yb::pggate::PerformFuture::Get()                   // Second call of the PerformFuture::Get on same object
yb::pggate::PgDocResponse::Get()
yb::pggate::PgDocOp::~PgDocOp()
yb::pggate::PgDocReadOp::~PgDocReadOp()
...
yb::pggate::PgDml::~PgDml()
yb::pggate::PgDmlRead::~PgDmlRead()
yb::pggate::PgSelect::~PgSelect()
...
yb::pggate::PgMemctx::Clear()
yb::pggate::PgMemctx::~PgMemctx()
...
yb::pggate::ClearGlobalPgMemctxMap()
YBCDestroyPgGate
YBOnPostgresBackendShutdown
quickdie                                           // Caused by interruption by the SIGQUIT signal
...
std::__1::future<yb::pggate::PerformResult>::get()
yb::pggate::PerformFuture::Get()                   // First call of the PerformFuture::Get
yb::pggate::PgDocResponse::Get()
yb::pggate::PgDocOp::GetResult(std::__1::list<yb::pggate::PgDocResult, std::__1::allocator<yb::pggate::PgDocResult> >*)
yb::pggate::PgDml::FetchDataFromServer()
yb::pggate::PgDml::Fetch(int, unsigned long*, bool*,
yb::pggate::PgApiImpl::DmlFetch(yb::pggate::PgStatement*, int, unsigned long*,
YBCPgDmlFetch
ybcFetchNextHeapTuple
ybc_getnext_heaptuple
ybc_systable_getnext
systable_getnext
findDependentObjects
performDeletion
RemoveTempRelations
RemoveTempRelationsCallback
shmem_exit
proc_exit_prepare
proc_exit
PostgresMain
BackendRun
BackendStartup
ServerLoop
PostmasterMain
PostgresServerProcessMain
main
```

In this stack the `PerformFuture::Get` method is called on same object twice. But the `PerformFuture` object is designed to call `Get` method only once. After the first call the `PerformFuture::Valid` method should return `false` and `Get` method should not be called. But in the above stack the second call of the `PerformFuture::Get`method is done before the first one is returned (due to interruption by the `SIGQUIT` signal).

To handle this situation `session_` field is set to `null` at the very beginning of the `PerformFuture::Get`. In case `session_` is `null` the `PerformFuture::Valid` returns `false`.

**Part #2:** Access deleted `PgApiImpl` object
The `YBCDestroyPgGate` function destroys the `PgApiImpl` object and then calls the `ClearGlobalPgMemctxMap` function. But this function may call the code which access the `PgApiImpl` object fields. Here is the stack trace

```
std::__1::unique_ptr<yb::pggate::PgClient::Impl, std::__1::default_delete<yb::pggate::PgClient::Impl> >::operator->() const
yb::pggate::PgClient::FinishTransaction(yb::StronglyTypedBool<yb::pggate::Commit_Tag>, yb::StronglyTypedBool<yb::pggate::DdlMode_Tag>)
   yb::pggate::PgTxnManager::ExitSeparateDdlTxnMode(yb::StronglyTypedBool<yb::pggate::Commit_Tag>)
yb::pggate::PgTxnManager::FinishTransaction(yb::StronglyTypedBool<yb::pggate::Commit_Tag>)
yb::pggate::PgTxnManager::AbortTransaction()
yb::pggate::PgTxnManager::~PgTxnManager()
...
yb::pggate::PgSession::~PgSession()
...
yb::pggate::PgStatement::~PgStatement()
yb::pggate::PgDml::~PgDml()
yb::pggate::PgDmlRead::~PgDmlRead()
yb::pggate::PgSelect::~PgSelect()
...
yb::pggate::PgMemctx::Clear()
yb::pggate::PgMemctx::~PgMemctx()
...
yb::pggate::ClearGlobalPgMemctxMap()
...
```

Solution is to move PgMemctx map into the `PgApiImpl` object (this also fixes #7216)

**Part #3:** Access shut down `PgClient`object

The `~PgApiImpl()` explicitly shut downs `pg_client_` object but the `pg_session_` is still alive. And when it will be destroyed the pg_client_ object may be used.

The stack is

```
yb::pggate::PgClient::Impl::FinishTransaction(yb::StronglyTypedBool<yb::pggate::Commit_Tag>, yb::StronglyTypedBool<yb::pggate::DdlMode_Tag>)
yb::pggate::PgClient::FinishTransaction(yb::StronglyTypedBool<yb::pggate::Commit_Tag>, yb::StronglyTypedBool<yb::pggate::DdlMode_Tag>)
yb::pggate::PgTxnManager::ExitSeparateDdlTxnMode(yb::StronglyTypedBool<yb::pggate::Commit_Tag>)
yb::pggate::PgTxnManager::FinishTransaction(yb::StronglyTypedBool<yb::pggate::Commit_Tag>)
yb::pggate::PgTxnManager::AbortTransaction()
yb::pggate::PgTxnManager::~PgTxnManager()
...
yb::pggate::PgSession::~PgSession()
...
yb::pggate::PgApiImpl::~PgApiImpl()
...
YBCDestroyPgGate
YBOnPostgresBackendShutdown
quickdie
...
```

Solution is to explicitly destroy `pg_session_` before shutting down of `pg_client_`

Test Plan:
Jenkins

The following tests had crashed without the fix

```
./yb_build.sh asan --gtest_filter PgFKeyTest.AddFKCorrectnessOnTempTables
./yb_build.sh asan --gtest_filter PgCatalogPerfTest.CacheRefreshRPCCountWithPartitionTables
./yb_build.sh asan --gtest_filter PgMiniTest.BigInsertWithRestart
./yb_build.sh asan --gtest_filter AlterTableWithConcurrentTxnTest.TServerLeaderChange
```

Reviewers: dsrinivasan, jason, alex

Reviewed By: alex

Subscribers: mbautin, bogdan, yql

Differential Revision: https://phabricator.dev.yugabyte.com/D17259
d-uspenskiy added a commit that referenced this issue Aug 22, 2022
… on postgres shutdown

Summary:
The diff consists of 3 parts.

**Part #1:** Multiple call of the `PerformFuture::Get` method
In case of session close when temp tables exists the following stack is possible

```
std::__1::future<yb::pggate::PerformResult>::get()
yb::pggate::PerformFuture::Get()                   // Second call of the PerformFuture::Get on same object
yb::pggate::PgDocResponse::Get()
yb::pggate::PgDocOp::~PgDocOp()
yb::pggate::PgDocReadOp::~PgDocReadOp()
...
yb::pggate::PgDml::~PgDml()
yb::pggate::PgDmlRead::~PgDmlRead()
yb::pggate::PgSelect::~PgSelect()
...
yb::pggate::PgMemctx::Clear()
yb::pggate::PgMemctx::~PgMemctx()
...
yb::pggate::ClearGlobalPgMemctxMap()
YBCDestroyPgGate
YBOnPostgresBackendShutdown
quickdie                                           // Caused by interruption by the SIGQUIT signal
...
std::__1::future<yb::pggate::PerformResult>::get()
yb::pggate::PerformFuture::Get()                   // First call of the PerformFuture::Get
yb::pggate::PgDocResponse::Get()
yb::pggate::PgDocOp::GetResult(std::__1::list<yb::pggate::PgDocResult, std::__1::allocator<yb::pggate::PgDocResult> >*)
yb::pggate::PgDml::FetchDataFromServer()
yb::pggate::PgDml::Fetch(int, unsigned long*, bool*,
yb::pggate::PgApiImpl::DmlFetch(yb::pggate::PgStatement*, int, unsigned long*,
YBCPgDmlFetch
ybcFetchNextHeapTuple
ybc_getnext_heaptuple
ybc_systable_getnext
systable_getnext
findDependentObjects
performDeletion
RemoveTempRelations
RemoveTempRelationsCallback
shmem_exit
proc_exit_prepare
proc_exit
PostgresMain
BackendRun
BackendStartup
ServerLoop
PostmasterMain
PostgresServerProcessMain
main
```

In this stack the `PerformFuture::Get` method is called on same object twice. But the `PerformFuture` object is designed to call `Get` method only once. After the first call the `PerformFuture::Valid` method should return `false` and `Get` method should not be called. But in the above stack the second call of the `PerformFuture::Get`method is done before the first one is returned (due to interruption by the `SIGQUIT` signal).

To handle this situation `session_` field is set to `null` at the very beginning of the `PerformFuture::Get`. In case `session_` is `null` the `PerformFuture::Valid` returns `false`.

**Part #2:** Access deleted `PgApiImpl` object
The `YBCDestroyPgGate` function destroys the `PgApiImpl` object and then calls the `ClearGlobalPgMemctxMap` function. But this function may call the code which access the `PgApiImpl` object fields. Here is the stack trace

```
std::__1::unique_ptr<yb::pggate::PgClient::Impl, std::__1::default_delete<yb::pggate::PgClient::Impl> >::operator->() const
yb::pggate::PgClient::FinishTransaction(yb::StronglyTypedBool<yb::pggate::Commit_Tag>, yb::StronglyTypedBool<yb::pggate::DdlMode_Tag>)
   yb::pggate::PgTxnManager::ExitSeparateDdlTxnMode(yb::StronglyTypedBool<yb::pggate::Commit_Tag>)
yb::pggate::PgTxnManager::FinishTransaction(yb::StronglyTypedBool<yb::pggate::Commit_Tag>)
yb::pggate::PgTxnManager::AbortTransaction()
yb::pggate::PgTxnManager::~PgTxnManager()
...
yb::pggate::PgSession::~PgSession()
...
yb::pggate::PgStatement::~PgStatement()
yb::pggate::PgDml::~PgDml()
yb::pggate::PgDmlRead::~PgDmlRead()
yb::pggate::PgSelect::~PgSelect()
...
yb::pggate::PgMemctx::Clear()
yb::pggate::PgMemctx::~PgMemctx()
...
yb::pggate::ClearGlobalPgMemctxMap()
...
```

Solution is to move PgMemctx map into the `PgApiImpl` object (this also fixes #7216)

**Part #3:** Access shut down `PgClient`object

The `~PgApiImpl()` explicitly shut downs `pg_client_` object but the `pg_session_` is still alive. And when it will be destroyed the pg_client_ object may be used.

The stack is

```
yb::pggate::PgClient::Impl::FinishTransaction(yb::StronglyTypedBool<yb::pggate::Commit_Tag>, yb::StronglyTypedBool<yb::pggate::DdlMode_Tag>)
yb::pggate::PgClient::FinishTransaction(yb::StronglyTypedBool<yb::pggate::Commit_Tag>, yb::StronglyTypedBool<yb::pggate::DdlMode_Tag>)
yb::pggate::PgTxnManager::ExitSeparateDdlTxnMode(yb::StronglyTypedBool<yb::pggate::Commit_Tag>)
yb::pggate::PgTxnManager::FinishTransaction(yb::StronglyTypedBool<yb::pggate::Commit_Tag>)
yb::pggate::PgTxnManager::AbortTransaction()
yb::pggate::PgTxnManager::~PgTxnManager()
...
yb::pggate::PgSession::~PgSession()
...
yb::pggate::PgApiImpl::~PgApiImpl()
...
YBCDestroyPgGate
YBOnPostgresBackendShutdown
quickdie
...
```

Solution is to explicitly destroy `pg_session_` before shutting down of `pg_client_`

Original commit: 77396db / D17259

Test Plan:
Jenkins: rebase: 2.14

The following tests had crashed without the fix

```
./yb_build.sh asan --gtest_filter PgFKeyTest.AddFKCorrectnessOnTempTables
./yb_build.sh asan --gtest_filter PgCatalogPerfTest.CacheRefreshRPCCountWithPartitionTables
./yb_build.sh asan --gtest_filter PgMiniTest.BigInsertWithRestart
./yb_build.sh asan --gtest_filter AlterTableWithConcurrentTxnTest.TServerLeaderChange
```

Reviewers: dsrinivasan, alex, jason

Reviewed By: jason

Subscribers: yql, bogdan, mbautin

Differential Revision: https://phabricator.dev.yugabyte.com/D19048
@yugabyte-ci yugabyte-ci removed the kind/failing-test Tests and testing infra label Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

3 participants