Re: PATCH: pg_restore parallel-execution-deadlock issue

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Armin Schöffmann <armin(dot)schoeffmann(at)aegaeon(dot)de>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PATCH: pg_restore parallel-execution-deadlock issue
Date: 2016-05-27 12:03:14
Message-ID: CAB7nPqQSVN4xUoaZ7N-oMCc-0j0+UQ5j4DirV-BU3TyufKCrWw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, May 27, 2016 at 4:07 PM, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
> On Fri, May 27, 2016 at 3:05 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>
>> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>> > ea274b2 has changed the way disconnection is done is is now closing
>> > both the read and write pipes. So you may want to retry if things get
>> > better with the next round of minor releases.
>>
>> Hadn't paid attention to this thread before ...
>>
>> 1. Armin proposes using "shutdown(pipeWrite, SD_BOTH)" where the code
>> committed this morning (df8d2d8c4) has "closesocket(pipeWrite)".
>> I'd prefer to leave it that way since it's the same as for the Unix case,
>> and Kyotaro-san says it works for him. Is there a reason we'd need
>> shutdown() instead?

Hm, OK.

>> 2. Armin proposes that WaitForTerminatingWorkers needs to do CloseHandle()
>> on the various thread handles. That sounds plausible but I don't know
>> enough Windows programming to know if it really matters.
>>
>> 3. Should we replace ExitThread() with _endthreadex()? Again, it
>> seems plausible but I'm not the person to ask.
>>
>
> I think point (2) and (3) are related because using _endthreadex won't close
> the thread handle explicitly [1].

Yep.

> [1] - https://msdn.microsoft.com/en-us/library/kdzttdcb.aspx
> Refer line "_endthread automatically closes the thread handle, whereas
> _endthreadex does not."

And the rest of the sentence:
Therefore, when you use _beginthread and _endthread, do not explicitly
close the thread handle by calling the Win32 CloseHandle API. This
behavior differs from the Win32 ExitThread API.

Personally I understand that as well as for the first part: when using
_beginthreadex and _endthreadex, be sure to call CloseHandle() to
explicitely close the thread handle.

And based on the second part if we use ExitThread after beginning a
thread with _beginthreadex we would get unreliable behavior. I guess
you don't need a patch? Because by looking again at this thread and
the windows docs what we have now is unpredictable.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nikolay Shaplov 2016-05-27 13:41:41 Re: [PROPOSAL] Move all am-related reloption code into src/backend/access/[am-name] and get rid of relopt_kind
Previous Message Léonard Benedetti 2016-05-27 11:56:55 Fix a typo in 9.6 release notes