yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
8.92k stars 1.06k forks source link

[YSQL] ASAN reported memory leaks for '\d' command #1049

Open nocaway opened 5 years ago

nocaway commented 5 years ago

Jira Link: DB-1257 Reproducible case: Uncomment '\d' command at the end of test file "yb_bit.sql" and run the test with ASAN build.

Symptoms ASAN reported memory leaks in psql when '\d' - describe command - is used. This occurs in PG 11 but not PG 10. Af the first glance, the leaking callstack showed the issue was in client application such as "psql"

+ =================================================================
+ ==12750==ERROR: LeakSanitizer: detected memory leaks
+ 
+ Direct leak of 208 byte(s) in 1 object(s) allocated from:
+     #0 0x4eba8f in malloc /n/jenkins/thirdparty/yugabyte-thirdparty-2019-02-28T08_28_04/thirdparty/build/common/llvm-7.0.1.src/../../../src/llvm-7.0.1.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:146
+     #1 0x7f776e531240 in PQmakeEmptyPGresult /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/interfaces/libpq/../../../../../../src/postgres/src/interfaces/libpq/fe-exec.c:146:24
+     #2 0x7f776e550ada in getRowDescriptions /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/interfaces/libpq/../../../../../../src/postgres/src/interfaces/libpq/fe-protocol3.c
+     #3 0x7f776e54f03e in pqParseInput3 /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/interfaces/libpq/../../../../../../src/postgres/src/interfaces/libpq/fe-protocol3.c:293:11
+     #4 0x7f776e536817 in PQgetResult /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/interfaces/libpq/../../../../../../src/postgres/src/interfaces/libpq/fe-exec.c:1796:3
+     #5 0x7f776e537107 in PQexecFinish /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/interfaces/libpq/../../../../../../src/postgres/src/interfaces/libpq/fe-exec.c:2069:19
+     #6 0x53bf59 in PSQLexec /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/common.c:721:8
+     #7 0x54fe57 in describeOneTableDetails /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/describe.c:2060:12
+     #8 0x54e3b3 in describeTableDetails /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/describe.c:1418:8
+     #9 0x5319ef in exec_command_d /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/command.c:700:16
+     #10 0x52be70 in exec_command /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/command.c:313:12
+     #11 0x52b9f7 in HandleSlashCmds /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/command.c:215:11
+     #12 0x5634e4 in MainLoop /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/mainloop.c:486:22
+     #13 0x52e79e in process_file /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/command.c:3544:11
+     #14 0x576e21 in main /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/startup.c:375:21
+     #15 0x7f776d40a824 in __libc_start_main /tmp/glibc-20181130-26094-cs1x60/glibc-2.23/csu/../csu/libc-start.c:289
+ 
+ Objects leaked above:
+ 0x611000010bc0 (208 bytes)
+ 
+ Indirect leak of 2048 byte(s) in 1 object(s) allocated from:
+     #0 0x4eba8f in malloc /n/jenkins/thirdparty/yugabyte-thirdparty-2019-02-28T08_28_04/thirdparty/build/common/llvm-7.0.1.src/../../../src/llvm-7.0.1.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:146
+     #1 0x7f776e533931 in pqResultAlloc /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/interfaces/libpq/../../../../../../src/postgres/src/interfaces/libpq/fe-exec.c:594:28
+     #2 0x7f776e550b89 in getRowDescriptions /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/interfaces/libpq/../../../../../../src/postgres/src/interfaces/libpq/fe-protocol3.c:513:4
+     #3 0x7f776e54f03e in pqParseInput3 /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/interfaces/libpq/../../../../../../src/postgres/src/interfaces/libpq/fe-protocol3.c:293:11
+     #4 0x7f776e536817 in PQgetResult /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/interfaces/libpq/../../../../../../src/postgres/src/interfaces/libpq/fe-exec.c:1796:3
+     #5 0x7f776e537107 in PQexecFinish /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/interfaces/libpq/../../../../../../src/postgres/src/interfaces/libpq/fe-exec.c:2069:19
+     #6 0x53bf59 in PSQLexec /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/common.c:721:8
+     #7 0x54fe57 in describeOneTableDetails /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/describe.c:2060:12
+     #8 0x54e3b3 in describeTableDetails /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/describe.c:1418:8
+     #9 0x5319ef in exec_command_d /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/command.c:700:16
+     #10 0x52be70 in exec_command /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/command.c:313:12
+     #11 0x52b9f7 in HandleSlashCmds /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/command.c:215:11
+     #12 0x5634e4 in MainLoop /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/mainloop.c:486:22
+     #13 0x52e79e in process_file /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/command.c:3544:11
+     #14 0x576e21 in main /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/startup.c:375:21
+     #15 0x7f776d40a824 in __libc_start_main /tmp/glibc-20181130-26094-cs1x60/glibc-2.23/csu/../csu/libc-start.c:289
+ 
+ Objects leaked above:
+ 0x61d00002e480 (2048 bytes)
+ 
+ SUMMARY: AddressSanitizer: 2256 byte(s) leaked in 2 allocation(s).
======================================================================
tedyu commented 1 year ago

I didn't find yb_bit.sql in the source code. @nocaway Do you mind pointing me where I can find the file ?

tedyu commented 1 year ago

I was tracing the leak reported in the first hunk above:

#6 0x53bf59 in PSQLexec /net/centos-gcp-cloud-jenkins-slave-71b/share/jenkins/workspace/yugabyte-phabricator@4/src/postgres/src/bin/psql/../../../../../../src/postgres/src/bin/psql/common.c:721:8

which, at the time of creation of this issue, called PQexecFinish. Nowadays, I couldn't find PQexecFinish in the whole of common.c

Actually the above observation applies to both reported leaks because both involve PQexecFinish.

tedyu commented 1 year ago

I have examined git log around libpq/fe-exec.c and related files to see if there has been some leak fix upstream.

There was none in PG 11 branch which we don't already have.

bmatican commented 1 year ago

@m-iancu Was this a legitimate memory leak, in the product? Is this lower pri, as it only affects the PG backend that the user is connected to?