pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tv@fuzzy.cz>
To: pgsql-bugs@postgresql.org
Subject: overwriting an existing .so while being used crashes the server process
Date: Wed, 30 May 2012 22:29:48 +0200
Message-ID: <4FC6833C.6080501@fuzzy.cz> (raw)

Hi,

whenever I run a C-function (part of an .so file) and the file is
overwritten, the connection crashes. Tested on 9.1.3 and 9.2-beta1.

It's 100% reproducible:

 1) compile the attached file and copy the .so to pkglibdir

    $ gcc -I/home/tomas/tmp/postgresql-9.1.2/src/include testcomp.c
          -shared -fPIC -o testcomp.so

    $ cp testcomp.so `pg_config --pkglibdir`

 2) create a function, calling the .so

    CREATE FUNCTION test_computation()
           RETURNS void
           AS 'testcomp','test_computation'
           LANGUAGE C STRICT;

 3) call the function and while it's running, repeat step (1).

 4) an example of the output

    WARNING:  i = 532000000 v = 141512000266000000
    WARNING:  i = 533000000 v = 142044500266500000
    WARNING:  i = 534000000 v = 142578000267000000
    The connection to the server was lost. Attempting reset: Failed.

    and a log says this

    LOG:  server process (PID 17161) was terminated by signal 7: Bus
          error
    LOG:  terminating any other active server processes
    WARNING:  terminating connection because of crash of another server
              process
    ...

This does not happen when the .so is removed or just touched, it needs
to be overwritten (although with a file that's binary exactly the same).

Basic info about the box: Linux rimmer 3.3.2-gentoo #1 SMP PREEMPT Wed
Apr 18 14:54:04 CEST 2012 x86_64 Intel(R) Core(TM) i5-2500K CPU @
3.30GHz GenuineIntel GNU/Linux

kind regards
Tomas

Attachments:

testcomp.c (text/x-c, 975B) download #include <stdio.h> #include <stdlib.h> #include "postgres.h" #include "funcapi.h" #include "miscadmin.h" PG_MODULE_MAGIC; /* * gcc -I/home/tomas/tmp/postgresql-9.1.2/src/include testcomp.c -shared -fPIC * -o testcomp.so * * CREATE FUNCTION test_computation() * RETURNS void * AS 'testcomp','test_computation' * LANGUAGE C STRICT; * * */ PG_FUNCTION_INFO_V1(test_computation); Datum test_computation(PG_FUNCTION_ARGS); void *print_message_function( void *ptr ); Datum test_computation(PG_FUNCTION_ARGS) { int64 result; char * message1 = print_message_function(&result); PG_RETURN_VOID(); } void *print_message_function( void *ptr ) { int64 i; int64 x = 0; /* let's torture the CPU a bit ... */ for (i = 0; i < 5000000000; i++) { x = x + i; if (i % 1000000 == 0) { /* needed for a quick response to cancel-query */ elog(WARNING, "i = %ld v = %ld", i, x); } } *((int64*)ptr) = x; }

view thread (6+ messages)  latest in thread

Message-ID: <4FC6833C.6080501@fuzzy.cz>
Permalink:  ../4FC6833C.6080501@fuzzy.cz/
Also on:    postgresql.org/message-id/4FC6833C.6080501@fuzzy.cz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tv@fuzzy.cz
  Subject: Re: overwriting an existing .so while being used crashes the server process
  In-Reply-To: <4FC6833C.6080501@fuzzy.cz>
  References: <4FC6833C.6080501@fuzzy.cz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox