| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
|---|---|
| To: | AgentM <agentm(at)themactionfaction(dot)com> | 
| Cc: | pgsql-patches(at)postgresql(dot)org | 
| Subject: | Re: BUG #1467: fe_connect doesn't handle EINTR right | 
| Date: | 2005-08-11 22:56:49 | 
| Message-ID: | 28294.1123801009@sss.pgh.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-patches | 
AgentM <agentm(at)themactionfaction(dot)com> writes:
> Attached is a patch which corrects the behavior. I verified that the  
> patch does not interfere with normal operation (using psql) but  
> unfortunately the code path is virtually impossible to test without a  
> really slow connection to a postgresql server [which I thankfully  
> don't have]. To test the patch, you would need to send an interrupt  
> at the exact time that the kernel is connect()ing in blocking mode-  
> good luck.
I've applied a simplified version of this patch --- there is no need to
duplicate the functionality that the calling level must have anyway.
regards, tom lane
Index: fe-connect.c
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v
retrieving revision 1.316
retrieving revision 1.317
diff -c -r1.316 -r1.317
*** fe-connect.c	9 Aug 2005 05:14:26 -0000	1.316
--- fe-connect.c	11 Aug 2005 22:53:41 -0000	1.317
***************
*** 1082,1096 ****
  					 * since we are in nonblock mode.  If it does, well,
  					 * too bad.
  					 */
- 			retry_connect:
  					if (connect(conn->sock, addr_cur->ai_addr,
  								addr_cur->ai_addrlen) < 0)
  					{
- 						if (SOCK_ERRNO == EINTR)
- 							/* Interrupted system call - just try again */
- 							goto retry_connect;
  						if (SOCK_ERRNO == EINPROGRESS ||
  							SOCK_ERRNO == EWOULDBLOCK ||
  							SOCK_ERRNO == 0)
  						{
  							/*
--- 1082,1093 ----
  					 * since we are in nonblock mode.  If it does, well,
  					 * too bad.
  					 */
  					if (connect(conn->sock, addr_cur->ai_addr,
  								addr_cur->ai_addrlen) < 0)
  					{
  						if (SOCK_ERRNO == EINPROGRESS ||
  							SOCK_ERRNO == EWOULDBLOCK ||
+ 							SOCK_ERRNO == EINTR ||
  							SOCK_ERRNO == 0)
  						{
  							/*
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2005-08-12 01:02:03 | Re: data on devel code perf dip | 
| Previous Message | Bruce Momjian | 2005-08-11 22:14:10 | Re: [HACKERS] For review: Server instrumentation patch |