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] Assertion failure: Assert(portal->status != PORTAL_DONE) triggered by unique key violation #10744

Open
mtakahar opened this issue Dec 1, 2021 · 1 comment
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@mtakahar
Copy link
Contributor

mtakahar commented Dec 1, 2021

Jira Link: DB-755

Description

Unique key violation leads to server crash when the INSERT is preceded by a PL/pgSQL block that handled non-null violation exception.

Example:

yugabyte(26555)# DROP TABLE t1;
CREATE TABLE t1 (k int PRIMARY KEY);
DO $body$
BEGIN
  INSERT INTO t1 (k) VALUES (null);
EXCEPTION
  WHEN others THEN RAISE NOTICE '%', SQLERRM;
END;
$body$;
INSERT INTO t1 (k) VALUES (1);
INSERT INTO t1 (k) VALUES (1);

DROP TABLE
yugabyte(26555)# CREATE TABLE
yugabyte(26555)# yugabyte$# yugabyte$# yugabyte$# yugabyte$# yugabyte$# yugabyte$# NOTICE:  null value in column "k" violates not-null constraint
DO
yugabyte(26555)# INSERT 0 1
yugabyte(26555)# server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
()> ()> 

The backtrace and the failed ASSERT:

(lldb) Process 26963 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00007fff2035f92e libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
->  0x7fff2035f92e <+10>: jae    0x7fff2035f938            ; <+20>
    0x7fff2035f930 <+12>: movq   %rax, %rdi
    0x7fff2035f933 <+15>: jmp    0x7fff20359ad9            ; cerror_nocancel
    0x7fff2035f938 <+20>: retq   
Target 0: (postgres) stopped.
(lldb)  bt
bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff2035f92e libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff2038e5bd libsystem_pthread.dylib`pthread_kill + 263
    frame #2: 0x00007fff202e3406 libsystem_c.dylib`abort + 125
    frame #3: 0x00000001025f63bd postgres`ExceptionalCondition + 125 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/utils/error/assert.c:54
    frame #4: 0x000000010264a509 postgres`MarkPortalFailed + 57 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/utils/mmgr/portalmem.c:452
    frame #5: 0x00000001024139bf postgres`PortalRun + 1215 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/tcop/pquery.c:839
    frame #6: 0x0000000102410e7b postgres`exec_simple_query + 1451 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/tcop/postgres.c:1161
    frame #7: 0x000000010240f985 postgres`yb_exec_simple_query_impl + 21 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/tcop/postgres.c:4383
    frame #8: 0x000000010240f8c6 postgres`yb_exec_query_wrapper + 182 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/tcop/postgres.c:4368
    frame #9: 0x000000010240be15 postgres`yb_exec_simple_query + 69 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/tcop/postgres.c:4398
    frame #10: 0x000000010240ac3b postgres`PostgresMain + 2907 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/tcop/postgres.c:5006
    frame #11: 0x000000010233b774 postgres`BackendRun + 836 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/postmaster/postmaster.c:4470
    frame #12: 0x000000010233a962 postgres`BackendStartup + 626 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/postmaster/postmaster.c:4136
    frame #13: 0x000000010233959c postgres`ServerLoop + 956 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/postmaster/postmaster.c:1754
    frame #14: 0x000000010233674a postgres`PostmasterMain + 6906 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/postmaster/postmaster.c:1417
    frame #15: 0x000000010223c3e4 postgres`PostgresServerProcessMain + 772 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/main/main.c:234
    frame #16: 0x000000010223c812 postgres`main + 34
    frame #17: 0x00007fff203a9f3d libdyld.dylib`start + 1
(lldb) f 4
f 4
frame #4: 0x000000010264a509 postgres`MarkPortalFailed + 57 at /Users/mtakahara/code/yugabyte-db4/src/postgres/src/backend/utils/mmgr/portalmem.c:452
   449 	MarkPortalFailed(Portal portal)
   450 	{
   451 		/* Perform the state transition */
-> 452 		Assert(portal->status != PORTAL_DONE);
    		^
   453 		portal->status = PORTAL_FAILED;
   454 	
   455 		/*
(lldb) p portal->status
p portal->status
(PortalStatus) $4 = PORTAL_DONE
(lldb) 
@mtakahar mtakahar added kind/bug This issue is a bug area/ysql Yugabyte SQL (YSQL) labels Dec 1, 2021
@mtakahar
Copy link
Contributor Author

mtakahar commented Dec 1, 2021

According to @d-uspenskiy, this issue is related to the code introduced as a part of the change for #9467, and I've verified that his suggested change fixes this, too.

@pkj415 can you please take a look?

@mtakahar mtakahar assigned mtakahar and pkj415 and unassigned mtakahar Dec 1, 2021
@yugabyte-ci yugabyte-ci added the priority/medium Medium priority issue label Jun 8, 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
Status: No status
Development

No branches or pull requests

3 participants