pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Victor Spirin <v.spirin@postgrespro.ru>
To: pgsql-hackers@lists.postgresql.org
Subject: Sometimes the output to the stdout in Windows disappears
Date: Mon, 31 Aug 2020 21:20:28 +0300
Message-ID: <ac976d8c-03df-d6b8-025c-15a2de8d9af1@postgrespro.ru> (raw)

Hi!

Sometimes the output to stdout on Windows on multicore machines does not 
go through after connecting and disconnecting to the server using the 
PQconnectdbParams and PQfinish functions. I tested on 6 cores.

First we appeared this in some pgbench tests.  Then we found that this 
happens on any console program using PQconnectdbParams and PQfinish.

I am attaching a patch and a script for testing.

-- 
Victor Spirin
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

Attachments:

stdout.patch (text/plain, 527B) download diff --git a/src/port/snprintf.c b/src/port/snprintf.c index 83a8103..17dc505 100644 --- a/src/port/snprintf.c +++ b/src/port/snprintf.c @@ -313,6 +313,14 @@ flushbuffer(PrintfTarget *target) target->failed = true; } target->bufptr = target->bufstart; + /* + * Sometimes the output to stdout on Windows on multicore machines + * does not go through after connecting and disconnecting to the server + * using the PQconnectdbParams and PQfinish functions. + */ +#ifdef WIN32 + fflush(target->stream); +#endif }
test_clusterdb.pl (text/plain, 412B) download use IPC::Run; my $clopts = '-p 5432 -e --dbname=postgres -U postgres'; my $stdout; my $stderr; my @cmd = ('clusterdb', split /\s+/, $clopts); my $ch; for (my $i =0; $i < 2*4096; $i++) { $ch = IPC::Run::run(\@cmd, '>', \$stdout, '2>', \$stderr); if(not defined $stdout) { print($i.": not defined\n"); } if($stdout eq '') { print($i.": stdout is empty\n"); } if ( ($i % 100) == 0){ print("$i\n"); } }

view thread (16+ messages)  latest in thread

Message-ID: <ac976d8c-03df-d6b8-025c-15a2de8d9af1@postgrespro.ru>
Permalink:  ../ac976d8c-03df-d6b8-025c-15a2de8d9af1@postgrespro.ru/
Also on:    postgresql.org/message-id/ac976d8c-03df-d6b8-025c-15a2de8d9af1@postgrespro.ru

 ·  · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: v.spirin@postgrespro.ru, pgsql-hackers@lists.postgresql.org
  Subject: Re: Sometimes the output to the stdout in Windows disappears
  In-Reply-To: <ac976d8c-03df-d6b8-025c-15a2de8d9af1@postgrespro.ru>

* 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