Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iO1zz-0007tJ-QD for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Oct 2019 15:59:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iO1zy-0003q7-H7 for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Oct 2019 15:59:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iO1zy-0003pz-6l for pgsql-hackers@lists.postgresql.org; Fri, 25 Oct 2019 15:59:34 +0000 Received: from [212.85.157.172] (helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iO1zw-00070O-0q for pgsql-hackers@lists.postgresql.org; Fri, 25 Oct 2019 15:59:33 +0000 Received: from firost (unknown [88.190.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 874211FD85 for ; Fri, 25 Oct 2019 17:59:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1572019170; bh=O8Bi3kihUesYfeaijfxnH/rxrYoDVbW42q/7uMnNQAk=; h=Date:From:To:Subject:From; b=XoQ2d7GeE0NWK8UyNqZrgbFun8siUbVUkuh7eMCRpHcuvAZqws/YPG9gRkRbf4S9Y 7Uh2JUHp0fETpXR+Sf4na+8wk3XK3Ggqh7zSOeGfmmDGkWY1t65VmJKGdOm0omgiF2 S2F/SePAIVK4h7mUpniFLtSkJuoxXaTWfmNqvUTE= Date: Fri, 25 Oct 2019 17:59:29 +0200 From: Jehan-Guillaume de Rorthais To: pgsql-hackers@lists.postgresql.org Subject: segmentation fault when cassert enabled Message-ID: <20191025175929.7e90dbf5@firost> Organization: Dalibo MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/9N6Uf8HyarwYF6jQy00n++P" X-Host-Lookup-Failed: Reverse DNS lookup failed for 212.85.157.172 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --MP_/9N6Uf8HyarwYF6jQy00n++P Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi list, When investigating for the bug reported in thread "logical replication - negative bitmapset member not allowed", I found a way to seg fault postgresql only when cassert is enabled. See the scenario in attachment. When executed against binaries compiled with --enable-cassert, I have the following error in logs: LOG: 00000: background worker "logical replication worker" (PID 761) was terminated by signal 11: Segmentation fault Here is the stack trace: #0 in slot_store_cstrings (slot=0x55a3c6973b48, rel=0x55a3c6989468, values=0x7ffe08ae67b0) at worker.c:330 #1 in apply_handle_update (s=0x7ffe08aeddb0) at worker.c:712 #2 in apply_dispatch (s=0x7ffe08aeddb0) at worker.c:968 #3 in LogicalRepApplyLoop (last_received=87957952) at worker.c:1175 #4 in ApplyWorkerMain (main_arg=0) at worker.c:1733 #5 in StartBackgroundWorker () at bgworker.c:834 #6 in do_start_bgworker (rw=0x55a3c68c16d0) at postmaster.c:5763 #7 in maybe_start_bgworkers () at postmaster.c:5976 #8 in sigusr1_handler (postgres_signal_arg=10) at postmaster.c:5161 #9 #10 in __GI___select (nfds=6, readfds=0x7ffe08aee680, writefds=0x0, exceptfds=0x0, timeout=0x7ffe08aee700) at ../sysdeps/unix/sysv/linux/select.c:41 #11 in ServerLoop () at postmaster.c:1668 #12 in PostmasterMain (argc=3, argv=0x55a3c6899820) at postmaster.c:1377 #13 in main (argc=3, argv=0x55a3c6899820) at main.c:228 It leads to this conditional test in worker.c:slot_store_cstrings for (i = 0; i < natts; i++) { [...] if (!att->attisdropped && remoteattnum >= 0 && values[remoteattnum] != NULL) In gdb, I found remoteattnum seems to be not correctly initialized for the latest column the scenario adds in pgbench_branches: (gdb) p remoteattnum $1 = 32639 (gdb) p i $2 = 3 I hadn't time to digg further yet. However, I don't understand why this crash is triggered when cassert is enabled. Regards, --MP_/9N6Uf8HyarwYF6jQy00n++P Content-Type: application/octet-stream; name=logrep-cassert-crash.bash Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=logrep-cassert-crash.bash IyEvdXNyL2Jpbi9iYXNoCgojIGVudgpQR0JJTj0vdG1wL2ZpeC9iaW4KI1BHQklOPS91c3IvbGli L3Bvc3RncmVzcWwvMTIvYmluClBVQj0vdG1wL3B1YgpTVUI9L3RtcC9zdWIKUFVCX1BPUlQ9NTQz MgpTVUJfUE9SVD01NDMzClRTPSQoZGF0ZSArJUZUJVQpClBVQl9MT0c9IiRQVUIiLSIkVFMiLmxv ZwpTVUJfTE9HPSIkU1VCIi0iJFRTIi5sb2cKCnVuc2V0IFBHUE9SVCBQR0hPU1QgUEdEQVRBQkFT RSBQR0RBVEEgTERfTElCUkFSWV9QQVRICmV4cG9ydCBQR1VTRVI9cG9zdGdyZXMKZXhwb3J0IFBH T1BUSU9OUz0iLWMgY2xpZW50X21pbl9tZXNzYWdlcz1FUlJPUiIKZXhwb3J0IFBBVEg9IiR7UEdC SU59OiR7UEFUSH0iCgpmdW5jdGlvbiBsb2cgewogICAgTD0kMTsgc2hpZnQKICAgIGVjaG8gIiQo ZGF0ZSArJyVGICVUJykgJHtMfTogICRAIgp9CgojIGNsZWFudXAKcGtpbGwgInBnYmVuY2giCgpm b3IgaSBpbiAiJFBVQiIgIiRTVUIiOyBkbwogICAgdGVzdCAtZCAiJGkiIHx8IGNvbnRpbnVlCiAg ICB0ZXN0IC1mICIkaSIvcG9zdG1hc3Rlci5waWQgJiYgIiRQR0JJTiIvcGdfY3RsIC13IC1zIC1E ICIkaSIgLW0gaW1tZWRpYXRlIHN0b3A7CiAgICBsb2cgTE9HICJzdG9wcGVkIG9sZCBpbnN0YW5j ZSBpbiAkaTogJD8iCiAgIC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