Hi,

I have a bug in Windows 7 with max_files_per_process> 1200.

Using dup (0) in theĀ  function count_usable_fds more than 1200 times (0 = stdin) causes further unpredictable errors with file operations.

When I open a real file and use its descriptor for the dup, no error occurs. In the patch I check the file postgresql.conf


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

diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 8dd51f1..79054e5 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -828,6 +828,15 @@ count_usable_fds(int max_to_probe, int *usable_fds, int 
*already_open)
                ereport(WARNING, (errmsg("getrlimit failed: %m")));
 #endif                                                 /* HAVE_GETRLIMIT */
 
+       int fd_test = 0;
+#ifdef WIN32
+       /*
+        * we have error on Windows7 with max_files_per_process > 1200 when 
dup(0) - stdin
+        * make test on postgresql.conf file    
+        */
+       fd_test = _open(ConfigFileName, _O_RDONLY);
+       if (fd_test < 0) fd_test = 0; /* if was error then = stdin */
+#endif
        /* dup until failure or probe limit reached */
        for (;;)
        {
@@ -843,7 +852,7 @@ count_usable_fds(int max_to_probe, int *usable_fds, int 
*already_open)
                        break;
 #endif
 
-               thisfd = dup(0);
+               thisfd = dup(fd_test);
                if (thisfd < 0)
                {
                        /* Expect EMFILE or ENFILE, else it's fishy */
@@ -869,7 +878,9 @@ count_usable_fds(int max_to_probe, int *usable_fds, int 
*already_open)
        /* release the files we opened */
        for (j = 0; j < used; j++)
                close(fd[j]);
-
+#ifdef WIN32
+       if (fd_test > 0) _close(fd_test);
+#endif
        pfree(fd);
 
        /*

Reply via email to