Fix memory corruption in query supervisor

Various crashes were observed when query supervisor killed query because of timeouts. The crash messages suggested memory corruption like the following:

malloc(): unsorted double linked list corrupted
Fatal glibc error: malloc.c:2599 (sysmalloc): assertion failed: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)

The exact source of the issue is hard to debug, but here's a quick guess that seems to help.

Query supervisor uses Postgres' builtin RegisterTimeout function to register a timeout handler. As mentioned by timeout.c Postgres source file, this uses SIGALRM. This means that our timeout handler is called from a signal handler. As specified by POSIX only async-signal-safe functions can be called from a signal handler.

In our timeout handler we had a call to LOG_WARNING, which expands to a call to ereport. It is not specified whether this function is or isn't async-signal-safe, but we can safely assume that is isn't.

The fix is to remove that call.

Closes #280 (closed)

Merge request reports

Loading
Loading