Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1auhqv-00036k-DO for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Apr 2016 14:51:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1auhqv-0002XG-0Q for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Apr 2016 14:51:09 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1auhqt-0002UN-RN for pgsql-hackers@postgreSQL.org; Mon, 25 Apr 2016 14:51:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1auhqr-0001f4-B1 for pgsql-hackers@postgreSQL.org; Mon, 25 Apr 2016 14:51:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u3PEp4XA031418 for ; Mon, 25 Apr 2016 10:51:04 -0400 From: Tom Lane To: pgsql-hackers@postgreSQL.org Subject: Bogus cleanup code in PostgresNode.pm MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <31328.1461595720.0@sss.pgh.pa.us> Date: Mon, 25 Apr 2016 10:51:04 -0400 Message-ID: <31417.1461595864@sss.pgh.pa.us> X-Pg-Spam-Score: -2.9 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31328.1461595720.1@sss.pgh.pa.us> I noticed that even when they are successful, buildfarm members bowerbird and jacana tend to spew a lot of messages like this in their bin-check steps: Can't remove directory /home/pgrunner/bf/root/HEAD/pgsql.build/src/bin/scripts/tmp_check/data_main_DdUf/pgdata/global: Directory not empty at /usr/lib/perl5/5.8/File/Temp.pm line 898 Can't remove directory /home/pgrunner/bf/root/HEAD/pgsql.build/src/bin/scripts/tmp_check/data_main_DdUf/pgdata/pg_xlog: Directory not empty at /usr/lib/perl5/5.8/File/Temp.pm line 898 Can't remove directory /home/pgrunner/bf/root/HEAD/pgsql.build/src/bin/scripts/tmp_check/data_main_DdUf/pgdata: Permission denied at /usr/lib/perl5/5.8/File/Temp.pm line 898 Can't remove directory /home/pgrunner/bf/root/HEAD/pgsql.build/src/bin/scripts/tmp_check/data_main_DdUf: Directory not empty at /usr/lib/perl5/5.8/File/Temp.pm line 898 ### Signalling QUIT to 9156 for node "main" # Running: pg_ctl kill QUIT 9156 What is happening here is that the test script is not bothering to do an explicit $node->stop operation, and if it doesn't, the automatic cleanup steps happen in the wrong order: the File::Temp destructor for the temp data directory runs before PostgresNode.pm's DESTROY function, which is what's issuing the "pg_ctl kill" command. On Unix that's just messy, but on Windows it fails because you can't delete a process's working directory. I am not sure whether this is guaranteed wrong or just sometimes wrong; the Perl docs I can find say that destructors are run in unspecified order once interpreter shutdown begins. But by adding some debug printout I was able to verify on my own machine that the data directory was already gone when DESTROY runs. I believe we can fix this by forcing postmaster shutdown in an END routine instead of a DESTROY routine, and hence propose the attached patch, which does things in the right order for me. I'm a pretty poor Perl programmer, so I'd appreciate somebody vetting this. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="properly-timed-PostgresNode-shutdown.patch"; charset="us-ascii" Content-ID: <31328.1461595720.2@sss.pgh.pa.us> Content-Description: properly-timed-PostgresNode-shutdown.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm index cd2e974..120f3f2 100644 *** a/src/test/perl/PostgresNode.pm --- b/src/test/perl/PostgresNode.pm *************** sub stop *** 662,667 **** --- 662,668 ---- my $pgdata =3D $self->data_dir; my $name =3D $self->name; $mode =3D 'fast' unless defined $mode; + return unless defined $self->{_pid}; print "### Stopping node \"$name\" using mode $mode\n"; TestLib::system_log('pg_ctl', '-D', $pgdata, '-m', $mode, 'stop'); $self->{_pid} =3D undef; *************** sub get_new_node *** 883,896 **** return $node; } =20=20 ! # Attempt automatic cleanup ! sub DESTROY { ! my $self =3D shift; ! my $name =3D $self->name; ! return unless defined $self->{_pid}; ! print "### Signalling QUIT to $self->{_pid} for node \"$name\"\n"; ! TestLib::system_log('pg_ctl', 'kill', 'QUIT', $self->{_pid}); } =20=20 =3Dpod --- 884,896 ---- return $node; } =20=20 ! # Attempt automatic cleanup of all created nodes ! sub END { ! foreach my $node (@all_nodes) ! { ! $node->teardown_node; ! } } =20=20 =3Dpod ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers ------- =_aaaaaaaaaa0--