Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id BC2FE1465A37 for ; Wed, 30 May 2012 17:30:04 -0300 (ADT) Received: from [2001:1528:137::f1] (helo=mail.gransy.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SZpWs-0007FR-F2 for pgsql-bugs@postgresql.org; Wed, 30 May 2012 20:30:03 +0000 Received: from antispam.gransy.com (antispam.gransy.com [77.78.104.124]) by mail.gransy.com (Postfix) with ESMTP id 94E09508921 for ; Wed, 30 May 2012 22:29:48 +0200 (CEST) Received: from mail.gransy.com ([82.208.44.189]) by antispam.gransy.com (antispam.gransy.com [77.78.104.124]) (amavisd-new, port 10024) with ESMTP id eRpTr5f+3siW for ; Wed, 30 May 2012 22:29:48 +0200 (CEST) Received: by mail.gransy.com (Postfix, from userid 5000) id 833BE508938; Wed, 30 May 2012 22:29:48 +0200 (CEST) Received: from [192.168.1.237] (ip-78-45-133-255.net.upcbroadband.cz [78.45.133.255]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.gransy.com (Postfix) with ESMTPSA id 4D6C1508921 for ; Wed, 30 May 2012 22:29:48 +0200 (CEST) Message-ID: <4FC6833C.6080501@fuzzy.cz> Date: Wed, 30 May 2012 22:29:48 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120420 Thunderbird/12.0 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: overwriting an existing .so while being used crashes the server process Content-Type: multipart/mixed; boundary="------------040109040105010208030309" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2001:1528:137::f1 (failed) X-Pg-Spam-Score: -1.1 (-) X-Archive-Number: 201205/225 X-Sequence-Number: 33196 This is a multi-part message in MIME format. --------------040109040105010208030309 Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: 7bit 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 --------------040109040105010208030309 Content-Type: text/x-c; name="testcomp.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="testcomp.c" #include #include #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; } --------------040109040105010208030309--