{"action":"created","issue":{"url":"https://api.github.com/repos/2ndQuadrant/pglogical/issues/26","repository_url":"https://api.github.com/repos/2ndQuadrant/pglogical","labels_url":"https://api.github.com/repos/2ndQuadrant/pglogical/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/2ndQuadrant/pglogical/issues/26/comments","events_url":"https://api.github.com/repos/2ndQuadrant/pglogical/issues/26/events","html_url":"https://github.com/2ndQuadrant/pglogical/issues/26","id":166428162,"number":26,"title":"ALWAYS and REPLICA triggers on subscriber cause segmentation fault","user":{"login":"carbonin","id":12697904,"avatar_url":"https://avatars.githubusercontent.com/u/12697904?v=3","gravatar_id":"","url":"https://api.github.com/users/carbonin","html_url":"https://github.com/carbonin","followers_url":"https://api.github.com/users/carbonin/followers","following_url":"https://api.github.com/users/carbonin/following{/other_user}","gists_url":"https://api.github.com/users/carbonin/gists{/gist_id}","starred_url":"https://api.github.com/users/carbonin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carbonin/subscriptions","organizations_url":"https://api.github.com/users/carbonin/orgs","repos_url":"https://api.github.com/users/carbonin/repos","events_url":"https://api.github.com/users/carbonin/events{/privacy}","received_events_url":"https://api.github.com/users/carbonin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-07-19T20:30:54Z","updated_at":"2016-09-17T02:01:50Z","closed_at":"2016-09-17T02:01:49Z","body":"### Versions\r\nPostgreSQL - 9.5.2\r\npglogical - 1.1.2\r\npglogical_output - 1.1.0\r\n\r\n### Steps to reproduce\r\n- Set up replication between two nodes (one provider and one subscriber)\r\n- Create a test table on both nodes:\r\n  - `CREATE TABLE test (id BIGINT PRIMARY KEY, data VARCHAR);`\r\n- Add the test table to the replication set\r\n- Set up a trivial audit trigger on the subscriber node:\r\n```sql\r\nCREATE TABLE IF NOT EXISTS audit_test(id BIGINT);\r\n\r\nCREATE OR REPLACE FUNCTION test_trigger()\r\nRETURNS TRIGGER AS\r\n$BODY$\r\nBEGIN\r\n        INSERT INTO audit_test VALUES (NEW.id);\r\n        RETURN NEW;\r\nEND;\r\n$BODY$\r\nLANGUAGE plpgsql;\r\n\r\nDROP TRIGGER IF EXISTS test_trigger ON test;\r\n\r\nCREATE TRIGGER test_trigger before INSERT ON test\r\nFOR EACH ROW EXECUTE PROCEDURE test_trigger();\r\n\r\nALTER TABLE test DISABLE TRIGGER test_trigger;\r\nALTER TABLE test ENABLE REPLICA TRIGGER test_trigger\r\n```\r\n- Insert a row into the table on the provider node.\r\n\r\n### Result\r\n\r\npostgresql.log output:\r\n```plain\r\n2016-07-19 20:13:15 GMT::578e836d.2352:@:[9042]:LOG:  worker process: pglogical apply 20587:1658409966 (PID 10399) was terminated by signal 11: Segmentation fault\r\n2016-07-19 20:13:15 GMT::578e836d.2352:@:[9042]:LOG:  terminating any other active server processes\r\n2016-07-19 20:13:15 GMT::578e89d9.2898:@:[10392]:WARNING:  terminating connection because of crash of another server process\r\n2016-07-19 20:13:15 GMT::578e89d9.2898:@:[10392]:DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.\r\n2016-07-19 20:13:15 GMT::578e89d9.2898:@:[10392]:HINT:  In a moment you should be able to reconnect to the database and repeat your command.\r\n2016-07-19 20:13:15 GMT:[local]:578e89db.289d:root@vmdb_production:[10397]:WARNING:  terminating connection because of crash of another server process\r\n2016-07-19 20:13:15 GMT:[local]:578e89db.289d:root@vmdb_production:[10397]:DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.\r\n2016-07-19 20:13:15 GMT:[local]:578e89db.289d:root@vmdb_production:[10397]:HINT:  In a moment you should be able to reconnect to the database and repeat your command.\r\n2016-07-19 20:13:15 GMT::578e836d.2352:@:[9042]:LOG:  all server processes terminated; reinitializing\r\n```\r\n\r\ngdb backtrace:\r\n```plain\r\n(gdb) bt\r\n#0  ExecBRInsertTriggers (estate=0x2c5b1b0, relinfo=0x2c4b610, slot=0x2c4ba00) at trigger.c:2060\r\n#1  0x00007fe3450a234d in handle_insert (s=s@entry=0x7ffe6e3b6650) at pglogical_apply.c:506\r\n#2  0x00007fe3450a31a8 in replication_handler (s=0x7ffe6e3b6650) at pglogical_apply.c:1312\r\n#3  apply_work (streamConn=streamConn@entry=0x2c1e3d0) at pglogical_apply.c:1582\r\n#4  0x00007fe3450a39da in pglogical_apply_main (main_arg=<optimized out>) at pglogical_apply.c:1977\r\n#5  0x000000000064847c in StartBackgroundWorker () at bgworker.c:726\r\n#6  0x00000000006538e5 in do_start_bgworker (rw=0x2baf380) at postmaster.c:5503\r\n#7  maybe_start_bgworker () at postmaster.c:5678\r\n#8  0x0000000000654465 in sigusr1_handler (postgres_signal_arg=<optimized out>)\tat postmaster.c:4939\r\n#9  <signal handler called>\r\n#10 0x00007fe34eb853f3 in __select_nocancel () at ../sysdeps/unix/syscall-template.S:81\r\n#11 0x0000000000468616 in ServerLoop ()\tat postmaster.c:1648\r\n#12 0x00000000006555e6 in PostmasterMain (argc=argc@entry=3, argv=argv@entry=0x2b81620)\tat postmaster.c:1292\r\n#13 0x0000000000469bde in main (argc=3,\targv=0x2b81620)\tat main.c:228\r\n```\r\n\r\nIt seems `aestate->estate->es_trig_tuple_slot` is not initialized in `handle_insert` before being passed to `ExecBRInsertTriggers`. I don't know enough about PostgreSQL internals to fix this myself, but hopefully this will get you guys close enough.\r\n\r\nThis happens for both `ENABLE REPLICA` and `ENABLE ALWAYS` triggers.\r\n\r\nLet me know if I can do anything else to help."},"comment":{"url":"https://api.github.com/repos/2ndQuadrant/pglogical/issues/comments/247742882","html_url":"https://github.com/2ndQuadrant/pglogical/issues/26#issuecomment-247742882","issue_url":"https://api.github.com/repos/2ndQuadrant/pglogical/issues/26","id":247742882,"user":{"login":"PJMODOS","id":761741,"avatar_url":"https://avatars.githubusercontent.com/u/761741?v=3","gravatar_id":"","url":"https://api.github.com/users/PJMODOS","html_url":"https://github.com/PJMODOS","followers_url":"https://api.github.com/users/PJMODOS/followers","following_url":"https://api.github.com/users/PJMODOS/following{/other_user}","gists_url":"https://api.github.com/users/PJMODOS/gists{/gist_id}","starred_url":"https://api.github.com/users/PJMODOS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PJMODOS/subscriptions","organizations_url":"https://api.github.com/users/PJMODOS/orgs","repos_url":"https://api.github.com/users/PJMODOS/repos","events_url":"https://api.github.com/users/PJMODOS/events{/privacy}","received_events_url":"https://api.github.com/users/PJMODOS/received_events","type":"User","site_admin":false},"created_at":"2016-09-17T02:01:49Z","updated_at":"2016-09-17T02:01:49Z","body":"This was actually fixed in master branch long time ago, we just didn't release fixed binaries yet."}}
{"actor":{"display_login":"PJMODOS"}}