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

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
 }
 
 
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");
        }
}

Reply via email to