Re: postgres.exe has encountered a problem on windows

Lists: pgsql-hackers
From: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Rushabh Lathia <rushabh(dot)lathia(at)enterprisedb(dot)com>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: postgres.exe has encountered a problem on windows
Date: 2011-04-01 14:53:08
Message-ID: AANLkTimtAQ0Sh-CNxZput7nPRwyfnzBcsUzN8c9LR=Pq@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Apr 1, 2011 at 6:51 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:

> On Fri, Apr 1, 2011 at 15:14, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
> wrote:
> > Problem:
> > ========
> >
> > On windows when we run 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?
>

Hmm, yes. It make more sense to add check for CurrentMemoryContext in
write_console().

PFA patch for the same.

Regards,
Rushabh Lathia
EnterpriseDB, The Enterprise PostgreSQL company.


From: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Rushabh Lathia <rushabh(dot)lathia(at)enterprisedb(dot)com>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: postgres.exe has encountered a problem on windows
Date: 2011-04-01 14:56:16
Message-ID: AANLkTimsYvzv-ii=ZEYtT0XhKxvam8GXJ+BXhqOmoDR7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Apr 1, 2011 at 8:23 PM, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>wrote:

>
>
> On Fri, Apr 1, 2011 at 6:51 PM, Magnus Hagander <magnus(at)hagander(dot)net>wrote:
>
>> On Fri, Apr 1, 2011 at 15:14, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
>> wrote:
>> > Problem:
>> > ========
>> >
>> > On windows when we run 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?
>>
>
> Hmm, yes. It make more sense to add check for CurrentMemoryContext in
> write_console().
>
> PFA patch for the same.
>

Oops missed the attachment.

Here it is ..

>
>
> Regards,
> Rushabh Lathia
> EnterpriseDB, The Enterprise PostgreSQL company.
>

Attachment Content-Type Size
win_crash_fix_v2.patch text/x-diff 830 bytes

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Rushabh Lathia <rushabh(dot)lathia(at)enterprisedb(dot)com>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: postgres.exe has encountered a problem on windows
Date: 2011-04-01 18:01:37
Message-ID: AANLkTikCy7m0UJkRLBQfkcFyAUPE6uPSOG90zi1wk-ZO@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Apr 1, 2011 at 16:56, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com> wrote:
>
>
> On Fri, Apr 1, 2011 at 8:23 PM, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
> wrote:
>>
>>
>> On Fri, Apr 1, 2011 at 6:51 PM, Magnus Hagander <magnus(at)hagander(dot)net>
>> wrote:
>>>
>>> On Fri, Apr 1, 2011 at 15:14, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
>>> wrote:
>>> > Problem:
>>> > ========
>>> >
>>> > On windows when we run 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?
>>
>> Hmm, yes. It make more sense to add check for CurrentMemoryContext in
>> write_console().
>>
>> PFA patch for the same.
>
> Oops missed the attachment.
>
> Here it is ..

Thanks, applied with the addition of a comment.

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


From: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Rushabh Lathia <rushabh(dot)lathia(at)enterprisedb(dot)com>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: postgres.exe has encountered a problem on windows
Date: 2011-04-02 05:53:27
Message-ID: BANLkTimoMqx_KODBt1-PqpntUZye==hAAg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Apr 1, 2011 at 11:31 PM, Magnus Hagander <magnus(at)hagander(dot)net>wrote:

> On Fri, Apr 1, 2011 at 16:56, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
> wrote:
> >
> >
> > On Fri, Apr 1, 2011 at 8:23 PM, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com
> >
> > wrote:
> >>
> >>
> >> On Fri, Apr 1, 2011 at 6:51 PM, Magnus Hagander <magnus(at)hagander(dot)net>
> >> wrote:
> >>>
> >>> On Fri, Apr 1, 2011 at 15:14, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com
> >
> >>> wrote:
> >>> > Problem:
> >>> > ========
> >>> >
> >>> > On windows when we run 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?
> >>
> >> Hmm, yes. It make more sense to add check for CurrentMemoryContext in
> >> write_console().
> >>
> >> PFA patch for the same.
> >
> > Oops missed the attachment.
> >
> > Here it is ..
>
> Thanks, applied with the addition of a comment.
>

Thanks Magnus.

regards,
Rushabh Lathia
EnterpriseDB, The Enterprise PostgreSQL company.