[HACKERS] edb-postgres.exe has encountered a problem on windows

2011-04-01 Thread Rushabh Lathia
Problem:


On windows when we run edb-postgres.exe without any command line args, its
getting crash or its showing error into Application logs of Event Viewer.

Analysis:
==

For any stderr we call the write_stderr() and write_stderr() calls the
write_console() for stderr. Now here write_console() using the palloc()
internally, which require the CurrentMemoryContext.

At the startup CurrentMemoryContext will be NULL, so palloc again calling
write_stderr(). So recursion has been started and its ending up with
exception.

Call stack for palloc() is:

main() - check_root() - write_stderr() - write_console() -
pgwin32_toUTF16() - palloc()

Fix:
=

Earlier  we used to call vfprintf() for windows stderr, which is now
replaced with write_console().
So to avoid the exception now, I added condition for CurrentMemoryContext
into write_stderr().

PFA patch to fix the same.

Regards,
Rushabh Lathia
EnterpriseDB http://www.enterprisedb.com/, The Enterprise
PostgreSQLhttp://www.enterprisedb.com/
 company.
Index: src/backend/utils/error/elog.c
===
RCS file: /repositories/postgreshome/cvs/pgsql/src/backend/utils/error/elog.c,v
retrieving revision 1.226
diff -c -p -r1.226 elog.c
*** src/backend/utils/error/elog.c	19 Aug 2010 22:55:01 -	1.226
--- src/backend/utils/error/elog.c	1 Apr 2011 14:08:38 -
*** write_stderr(const char *fmt,...)
*** 2759,2766 
  	}
  	else
  	{
! 		/* Not running as service, write to stderr */
! 		write_console(errbuf, strlen(errbuf));
  		fflush(stderr);
  	}
  #endif
--- 2759,2773 
  	}
  	else
  	{
! 		/* 
! 		 * To use the write_console we need memoryContext as its using palloc
! 		 * internally. When we don't have CurrentMemoryContext directly throw
! 		 * error at stderr.
! 		 */
! 		if (CurrentMemoryContext)
! 			write_console(errbuf, strlen(errbuf));
! 		else
! 			vfprintf(stderr, fmt, ap);
  		fflush(stderr);
  	}
  #endif

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] edb-postgres.exe has encountered a problem on windows

2011-04-01 Thread Magnus Hagander
On Fri, Apr 1, 2011 at 15:14, Rushabh Lathia rushabh.lat...@gmail.com wrote:
 Problem:
 

 On windows when we run edb-postgres.exe without any command line args, its
 getting crash or its showing error into Application logs of Event Viewer.

 Analysis:
 ==

 For any stderr we call the write_stderr() and write_stderr() calls the
 write_console() for stderr. Now here write_console() using the palloc()
 internally, which require the CurrentMemoryContext.

 At the startup CurrentMemoryContext will be NULL, so palloc again calling
 write_stderr(). So recursion has been started and its ending up with
 exception.

 Call stack for palloc() is:

 main() - check_root() - write_stderr() - write_console() -
 pgwin32_toUTF16() - palloc()

 Fix:
 =

 Earlier  we used to call vfprintf() for windows stderr, which is now
 replaced with write_console().
 So to avoid the exception now, I added condition for CurrentMemoryContext
 into write_stderr().

 PFA patch to fix the same.

What about the cases where we directly call write_console()? Do we
know we are good there, or should the check perhaps be made inside
write_console() instead of in the caller?

-- 
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] edb-postgres.exe has encountered a problem on windows

2011-04-01 Thread Robert Haas
On Fri, Apr 1, 2011 at 9:14 AM, Rushabh Lathia rushabh.lat...@gmail.com wrote:
 On windows when we run edb-postgres.exe ...

Did you intend to send this to an EDB-internal mailing list?

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] edb-postgres.exe has encountered a problem on windows

2011-04-01 Thread Heikki Linnakangas

On 01.04.2011 16:56, Robert Haas wrote:

On Fri, Apr 1, 2011 at 9:14 AM, Rushabh Lathiarushabh.lat...@gmail.com  wrote:

On windows when we run edb-postgres.exe ...


Did you intend to send this to an EDB-internal mailing list?


I think he just forgot to search  replace edb-postgres.exe to 
postgres.exe ;-). The issue was found originally on Advanced Server, but 
there is nothing EDB-specific there and the same bug is in community 
PostgreSQL.


--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] edb-postgres.exe has encountered a problem on windows

2011-04-01 Thread Rushabh Lathia
On Fri, Apr 1, 2011 at 7:26 PM, Robert Haas robertmh...@gmail.com wrote:

 On Fri, Apr 1, 2011 at 9:14 AM, Rushabh Lathia rushabh.lat...@gmail.com
 wrote:
  On windows when we run edb-postgres.exe ...

 Did you intend to send this to an EDB-internal mailing list?


Oops sorry, initially we found this bug with EDB.

But after looking into issue more I found that its also present into
postgreSQL.

Need to replace edb-postgres.exe with postgres.exe ..


Regards,
Rushabh Lathia
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company