apache / apache/age

`CREATE` a relationship whose endpoint is `NULL` crashes (Segfault) the backend

Open
#2,506 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C
Stars
4.8k
Forks
523
Avg merge
1d 2h
Merged PRs (30d)
9

Description

## Bug description

Writing a Cypher `CREATE` that creates a relationship whose start/end vertex is `NULL` — a value produced by an `OPTIONAL MATCH` that matched nothing — crashes the PostgreSQL backend with a segmentation fault. The backend process is terminated (`signal 11: Segmentation fault`) and the connection is dropped. Instead of raising a normal error for a NULL endpoint, AGE 1.8.0 dereferences the NULL vertex and crashes.

## Access method

- Command line via `psql`, inside the official Docker container `apache/age:1.8.0`

## Data setup

One graph with a single node. No edges.

```pgsql
CREATE EXTENSION IF NOT EXISTS age;
LOAD 'age';
SET search_path = ag_catalog, "$user", public;
SELECT create_graph('graph_test');
SELECT * FROM cypher('graph_test', $$ CREATE (a:Node {name: 'A'}) $$) AS (c0 agtype);
```

## Configuration

- None beyond the stock AGE extension. No additional modules (no PostGIS, etc.), default `search_path` handling as shown above.

## Command that triggers the crash

```pgsql
SELECT * FROM cypher('graph_test', $$ MATCH (a:Node {name: 'A'}) OPTIONAL MATCH (a)-[:LINK_TO]->(c) CREATE (a)-[:LINK_TO]->(c) $$) AS (c0 agtype);
```

The `OPTIONAL MATCH` does not match (no `LINK_TO` edge exists), so `c` is bound to `NULL`; the subsequent `CREATE (a)-[:LINK_TO]->(c)` then tries to create a relationship whose endpoint is `NULL`.

```
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 server log shows the backend being killed:

```
LOG: client backend (PID NNN) was terminated by signal 11: Segmentation fault
LOG: terminating any other active server processes
LOG: all server processes terminated; reinitializing
```

## Expected behavior

`OPTIONAL MATCH` implements a left join: when the pattern does not match, its variables are bound to `NULL`. The query is legal Cypher and should either execute normally, or raise a normal Cypher error (e.g., "endpoint is null") — it must not crash the backend process.

## Environment

- Version: 1.8.0 (official `apache/age:1.8.0` Docker image)
- PostgreSQL: 18.1 (Debian 18.1-1.pgdg13+2), x86_64

Contributor guide

Open the contributing guide

Research direction

Reproduce the query through the cypher entry point in the official apache/age:1.8.0 container, using the supplied graph setup and OPTIONAL MATCH followed by CREATE. Trace the relationship-creation path when the endpoint is NULL. Done means the query no longer causes a backend segmentation fault and instead completes or raises a normal Cypher error.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, postgresql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.