Re: [BUGS] Win32 deadlock detection not working for Postgres8beta1

"Magnus Hagander" <[email protected]>
Newsgroups gmane.comp.db.postgresql.devel.win32,gmane.comp.db.postgresql.devel.patches
Message-ID <[email protected]>
>>Bugger. I've found the reason for this - statement_timeout was also
>>broken. This was broken by the change of how signals are handled on
>>win32. We disabled APCs completely, but APCs were still used in the
>>timer emulation... This patch fixes this by re-enabling APCs 
>>in the main
>>check loop. The APC routine used by the timer code is very simple and
>>will not interfer with the signal stuff (which had problems 
>with socket
>>calls, as you probably recall).
>
>
>Sorry, this was a bit premature. There are a few more places that need
>to be cleane dup. I'll send a new patch in a couple of minutes.

Here's a more complete patch that addresses all the places where
WaitForxxx can block. The previous fix only fixed statement_timeout, not
the deadlock situation.

//Magnus


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [email protected] so that your
      message can get through to the mailing list cleanly
win32_timer.patch (application/octet-stream, 3.9 KB)
Index: src/include/miscadmin.h
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/include/miscadmin.h,v
retrieving revision 1.167
diff -c -r1.167 miscadmin.h
*** src/include/miscadmin.h	29 Aug 2004 05:06:55 -0000	1.167
--- src/include/miscadmin.h	2 Sep 2004 18:17:57 -0000
***************
*** 88,94 ****

  #define CHECK_FOR_INTERRUPTS() \
  do { \
! 	if (WaitForSingleObject(pgwin32_signal_event,0) == WAIT_OBJECT_0) \
  		pgwin32_dispatch_queued_signals(); \
  	if (InterruptPending) \
  		ProcessInterrupts(); \
--- 88,94 ----

  #define CHECK_FOR_INTERRUPTS() \
  do { \
! 	if (WaitForSingleObjectEx(pgwin32_signal_event,0,TRUE) == WAIT_OBJECT_0) \
  		pgwin32_dispatch_queued_signals(); \
  	if (InterruptPending) \
  		ProcessInterrupts(); \
Index: src/backend/port/win32/sema.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/port/win32/sema.c,v
retrieving revision 1.8
diff -c -r1.8 sema.c
*** src/backend/port/win32/sema.c	29 Aug 2004 05:06:46 -0000	1.8
--- src/backend/port/win32/sema.c	2 Sep 2004 18:50:32 -0000
***************
*** 233,239 ****
  		wh[0] = cur_handle;
  		wh[1] = pgwin32_signal_event;

! 		ret = WaitForMultipleObjects(2, wh, FALSE, (sops[0].sem_flg & IPC_NOWAIT) ? 0 : INFINITE);

  		if (ret == WAIT_OBJECT_0)
  		{
--- 233,239 ----
  		wh[0] = cur_handle;
  		wh[1] = pgwin32_signal_event;

! 		ret = WaitForMultipleObjectsEx(2, wh, FALSE, (sops[0].sem_flg & IPC_NOWAIT) ? 0 : INFINITE, TRUE);

  		if (ret == WAIT_OBJECT_0)
  		{
***************
*** 241,247 ****
  			sem_counts[sops[0].sem_num]--;
  			return 0;
  		}
! 		else if (ret == WAIT_OBJECT_0 + 1)
  		{
  			/* Signal event is set - we have a signal to deliver */
  			pgwin32_dispatch_queued_signals();
--- 241,247 ----
  			sem_counts[sops[0].sem_num]--;
  			return 0;
  		}
! 		else if (ret == WAIT_OBJECT_0 + 1 || ret == WAIT_IO_COMPLETION)
  		{
  			/* Signal event is set - we have a signal to deliver */
  			pgwin32_dispatch_queued_signals();
Index: src/backend/port/win32/socket.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/port/win32/socket.c,v
retrieving revision 1.5
diff -c -r1.5 socket.c
*** src/backend/port/win32/socket.c	30 Aug 2004 02:54:38 -0000	1.5
--- src/backend/port/win32/socket.c	2 Sep 2004 18:50:07 -0000
***************
*** 93,99 ****
  static int
  pgwin32_poll_signals(void)
  {
! 	if (WaitForSingleObject(pgwin32_signal_event, 0) == WAIT_OBJECT_0)
  	{
  		pgwin32_dispatch_queued_signals();
  		errno = EINTR;
--- 93,99 ----
  static int
  pgwin32_poll_signals(void)
  {
! 	if (WaitForSingleObjectEx(pgwin32_signal_event, 0, TRUE) == WAIT_OBJECT_0)
  	{
  		pgwin32_dispatch_queued_signals();
  		errno = EINTR;
***************
*** 130,138 ****

  	events[0] = pgwin32_signal_event;
  	events[1] = waitevent;
! 	r = WaitForMultipleObjects(2, events, FALSE, INFINITE);

! 	if (r == WAIT_OBJECT_0)
  	{
  		pgwin32_dispatch_queued_signals();
  		errno = EINTR;
--- 130,138 ----

  	events[0] = pgwin32_signal_event;
  	events[1] = waitevent;
! 	r = WaitForMultipleObjectsEx(2, events, FALSE, INFINITE, TRUE);

! 	if (r == WAIT_OBJECT_0 || r == WAIT_IO_COMPLETION)
  	{
  		pgwin32_dispatch_queued_signals();
  		errno = EINTR;
***************
*** 419,426 ****
  	}

  	events[numevents] = pgwin32_signal_event;
! 	r = WaitForMultipleObjectsEx(numevents + 1, events, FALSE, timeoutval, FALSE);
! 	if (r != WSA_WAIT_TIMEOUT && r != (WAIT_OBJECT_0 + numevents))
  	{
  		/*
  		 * We scan all events, even those not signalled, in case more than
--- 419,426 ----
  	}

  	events[numevents] = pgwin32_signal_event;
! 	r = WaitForMultipleObjectsEx(numevents + 1, events, FALSE, timeoutval, TRUE);
! 	if (r != WAIT_TIMEOUT && r != WAIT_IO_COMPLETION && r != (WAIT_OBJECT_0 + numevents))
  	{
  		/*
  		 * We scan all events, even those not signalled, in case more than
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.