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

[Bug]: Segfault when compressing a table in extension schema sql #4017

Closed
JamesGuthrie opened this issue Jan 24, 2022 · 1 comment · Fixed by #4020
Closed

[Bug]: Segfault when compressing a table in extension schema sql #4017

JamesGuthrie opened this issue Jan 24, 2022 · 1 comment · Fixed by #4020
Assignees
Labels

Comments

@JamesGuthrie
Copy link
Contributor

JamesGuthrie commented Jan 24, 2022

What type of bug is this?

Crash

What subsystems and features are affected?

Compression

What happened?

When creating and then compressing a hypertable during postgres extension installation, I get a segfault.

TimescaleDB version affected

2.5.1

PostgreSQL version used

14

What operating system did you use?

MacOS (also reproduced on Alpine docker image)

What installation method did you use?

self-hosted and Docker

What platform did you run on?

Other

Relevant log output and stack trace

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   postgres                      	       0x102501c28 EventTriggerAlterTableRelid + 28
1   postgres                      	       0x102529e94 AlterTableInternal + 68
2   timescaledb-tsl-2.5.1.so      	       0x1038b8240 tsl_process_compress_table + 3236
3   timescaledb-2.5.1.so          	       0x1037b0fa4 process_altertable_start + 1796
4   timescaledb-2.5.1.so          	       0x1037af9d4 timescaledb_ddl_command_start + 460
5   postgres                      	       0x10250db14 execute_extension_script + 1560
6   postgres                      	       0x10250ab24 CreateExtensionInternal + 752
7   postgres                      	       0x10250a754 CreateExtension + 428
8   postgres                      	       0x10268fd00 ProcessUtilitySlow + 896
9   postgres                      	       0x10268eed8 standard_ProcessUtility + 1056
10  timescaledb.so                	       0x102e8fa38 loader_process_utility_hook + 352
11  postgres                      	       0x10268e7e0 PortalRunUtility + 176
12  postgres                      	       0x10268e050 PortalRunMulti + 248
13  postgres                      	       0x10268db1c PortalRun + 452
14  postgres                      	       0x10268ccd8 exec_simple_query + 864
15  postgres                      	       0x10268ace8 PostgresMain + 2664
16  postgres                      	       0x10261bfd4 BackendRun + 64
17  postgres                      	       0x10261b774 ServerLoop + 2400
18  postgres                      	       0x1026192f0 PostmasterMain + 3740
19  postgres                      	       0x10259bc74 main + 636
20  dyld                          	       0x102cd90f4 start + 520


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000028be6   x1: 0x0000000148057e10   x2: 0xffffffffffffffff   x3: 0x0000000000000000
    x4: 0x0000000000000000   x5: 0x0000000000000000   x6: 0x0000000000000000   x7: 0x0000000000000dd0
    x8: 0x0000000000000000   x9: 0x0000000000000000  x10: 0x0000000000000001  x11: 0x0000000102782960
   x12: 0x0000000000000047  x13: 0x0000000143015580  x14: 0x0000000000000036  x15: 0x0000000000000001
   x16: 0x00000001973a16b0  x17: 0x0000800000000000  x18: 0x0000000000000000  x19: 0x0000000000000001
   x20: 0x0000000153857768  x21: 0x0000000000028be6  x22: 0x0000000000000004  x23: 0x0000000148057e10
   x24: 0x00000001480583bc  x25: 0x000000014805846c  x26: 0x000000013805a9b8  x27: 0x0000000000028be6
   x28: 0x0000000000015b43   fp: 0x000000016d9fd550   lr: 0x0000000102529e94
    sp: 0x000000016d9fd520   pc: 0x0000000102501c28 cpsr: 0x60001000
   far: 0x0000000000000010  esr: 0x92000046 (Data Abort) byte write Translation fault

Binary Images:
       0x102400000 -        0x1029b3fff postgres (*) <6cce5e59-ba14-3415-bbc9-dd00d8947b10> /opt/homebrew/*/postgres
       0x1038a0000 -        0x103903fff timescaledb-tsl-2.5.1.so (*) <0de67fe5-de96-3d1d-b0a3-40be201ee6c3> /opt/homebrew/*/timescaledb-tsl-2.5.1.so
       0x103788000 -        0x1037dffff timescaledb-2.5.1.so (*) <a1ddbd7d-1c80-3b95-9296-2fbce2e3d35b> /opt/homebrew/*/timescaledb-2.5.1.so
       0x102e8c000 -        0x102e93fff timescaledb.so (*) <766a7ec0-19df-35be-b38d-37020c880976> /opt/homebrew/*/timescaledb.so
       0x102cd4000 -        0x102d33fff dyld (*) <7e92b284-4b90-3b68-b31a-3ddc4c0e8d40> /usr/lib/dyld
               0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???

How can we reproduce the bug?

Place the following .control and .sql file in pg's extension directory, then in a psql shell execute CREATE EXTENSION tscrash;

// tscrash.control
comment = 'Timescale crasher'
default_version = '0.1'
module_pathname = '$libdir/tscrash'
relocatable = false
schema = tscrash
superuser = true
// tscrash--0.1.sql
CREATE SCHEMA IF NOT EXISTS _ps_trace;
CREATE SCHEMA IF NOT EXISTS ps_trace;

CREATE DOMAIN ps_trace.trace_id uuid NOT NULL CHECK (value != '00000000-0000-0000-0000-000000000000');

CREATE TABLE IF NOT EXISTS _ps_trace.span
(
    trace_id ps_trace.trace_id NOT NULL,
    span_id bigint NOT NULL,
    parent_span_id bigint NULL,
    start_time timestamptz NOT NULL,
    end_time timestamptz NOT NULL,
    PRIMARY KEY (span_id, trace_id, start_time),
    CHECK (start_time <= end_time)
);
CREATE INDEX ON _ps_trace.span USING BTREE (trace_id, parent_span_id) INCLUDE (span_id); -- used for recursive CTEs for trace tree queries

SELECT public.create_hypertable(
        '_ps_trace.span'::regclass,
        'start_time'::name,
        partitioning_column=>'trace_id'::name,
        number_partitions=>1::int,
        chunk_time_interval=>'07:57:57.345608'::interval,
        create_default_indexes=>false
    );

ALTER TABLE _ps_trace.span SET (timescaledb.compress, timescaledb.compress_segmentby='trace_id,span_id');
@RafiaSabih
Copy link
Contributor

I can confirm the bug is reproducible by above mentioned steps.

svenklemm added a commit to svenklemm/timescaledb that referenced this issue Jan 24, 2022
When ALTER TABLE SET (timescaledb.compress) is executed, the
compression table is created as part of this command. But when
run as part of an extension installation the EventTrigger for
ALTER TABLE does not get initialized leading to a segfault.

Fixes timescale#4017
@svenklemm svenklemm self-assigned this Jan 25, 2022
svenklemm added a commit to svenklemm/timescaledb that referenced this issue Jan 25, 2022
When ALTER TABLE SET (timescaledb.compress) is executed, the
compression table is created as part of this command. But when
run as part of an extension installation the EventTrigger for
ALTER TABLE does not get initialized leading to a segfault.

Fixes timescale#4017
svenklemm added a commit that referenced this issue Jan 25, 2022
When ALTER TABLE SET (timescaledb.compress) is executed, the
compression table is created as part of this command. But when
run as part of an extension installation the EventTrigger for
ALTER TABLE does not get initialized leading to a segfault.

Fixes #4017
svenklemm added a commit that referenced this issue Feb 8, 2022
When ALTER TABLE SET (timescaledb.compress) is executed, the
compression table is created as part of this command. But when
run as part of an extension installation the EventTrigger for
ALTER TABLE does not get initialized leading to a segfault.

Fixes #4017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants