Article delegate-en/3375 of [1-5160] on the server localhost:119
  upper oldest olders older1 this newer1 newers latest
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]
Newsgroups: mail-lists.delegate-en

[DeleGate-En] Re: Working with CFI
08 Jul 2006 04:27:46 GMT (Yutaka Sato)
The DeleGate Project


I fixed the problem and uploaded the fixed version as

In message <_A3374@delegate-en.ML_> on 07/07/06(21:59:35) I wrote:
 |I feel I'm getting so closer to the bug :)
 |It seems that the DeleGate is jumping to somewhere unknown, possibly to
 |address zero.  The strange report about MSXSL might be the result of it.
 |And I have a "good" news for you :)
 |I have found a path to reproduce the error constantly.
 | 1) MOUNT the error message (for 403-forbidden)
 | 2) cause repetitieve errors (getting forbidden responses)
 | 3) then DeleGate causes "penalty delay"
 | 4) then a socket for accepting clients is closed. possibly something is
 |    broken here.
 | 5) MOUNTed error message from a remote server is got.  something is broken
 |    here, maybe it's the socket environment to be inherited on spawn.
 | 6) client send the next request from the same connection on which it
 |    was rejected.  (the connection is kept alive in this case)
 | 7) then CFI process is spawned. the connection between it and the caller
 |    (parent) DeleGate process is broken, receiving empty environment,
 |    including broken jump-address (maybe zero) to a function.
 | 8) jumping to broken address causes SIGSEGV.
 |I'll inspect what happens in the phase 4-5) and fix it in the next release.

I found (was reminded) what the problem was :)

 a) a file descriptor bound to a socket is markd as a socket (by _SOCKET()
 b) when it is closed with fclose(), the mark is not cleared even after
   the file descriptor is released
 c) when another file (not a socket) is opened (by fopen() or open())
   reusing the file descripor, it is left marked as a socket
 d) I/O to the (non socket) file descriptor is redirected to send()/recv()
   via _write()/_read() then fails.

Your problem occurred because a pipe descriptor between DeleGate and a CFI
process is miss-marked as a socket by this problem.

The problem was in b).  When I did the porting onto Windows ten years ago,
I could not find a way to hook the fclose() to maintain the consistency
of the mark.
The original problem is that socket is not manupulated as a file on Win.
So I wrapped functions socket()/accept() to bind the handle to file
descriptor (osfhandle) and mark it as a socket.  dup()/dup2()/close() to
maintain the mark.  (the mark is an arrary to map fd to socket handle).
I/O functions read()/write()/fread()/fwrite()/fprintf()/...  are calling
_read()/_write() so I replaced it with my own _read()/_write() which
switches between __read/__write and recv/send depending on the mark.

Now, since version 8.11.0, fopen() is a macro to Xfopen() and it's easy
to extend it to maintain the mark, so I did it as the enclosed patch.

  9 9   Yutaka Sato <>
 ( ~ )  National Institute of Advanced Industrial Science and Technology
_<   >_ 1-1-4 Umezono, Tsukuba, Ibaraki, 305-8568 Japan
Do the more with the less -- B. Fuller

diff -cr delegate9.2.3-pre9x/rary/file.c delegate9.2.3-pre9y/rary/file.c
*** delegate9.2.3-pre9x/rary/file.c	Wed Jul  5 23:37:30 2006
--- delegate9.2.3-pre9y/rary/file.c	Sat Jul  8 12:12:23 2006
*** 1163,1167 ****
--- 1163,1180 ----
  		/* should suppress fclose(NULLFP()) ... */
+ 	if( isWindows() ){
+ 		int SocketOf(int fd);
+ 		int fd = fileno(fp);
+ 		int sock;
+ 		int rcode;
+ 		if( 0 < (sock = SocketOf(fd)) ){
+ 			porting_dbg("Xfclose(%d/%d) socket",fd,sock);
+ 			rcode = fclose(fp);
+ 			close(fd); /* unmark the fd as a socket */
+ 			return rcode;
+ 		}
+ 	}
  	return fclose(fp);
diff -cr delegate9.2.3-pre9x/src/version.c delegate9.2.3-pre9y/src/version.c
*** delegate9.2.3-pre9x/src/version.c	Fri Jul  7 07:13:28 2006
--- delegate9.2.3-pre9y/src/version.c	Sat Jul  8 12:12:33 2006
*** 16,23 ****
  #include "log.h"
  #define NAME	"DeleGate"
! #define VERSION	"9.2.3-pre9x"
! #define DATE	"July 7, 2006"
  #define DSTATUS	"BETA"
  #define AUTHOR	"Yutaka Sato"
  #define A_ORG	"National Institute of Advanced Industrial Science and Technology"
--- 16,23 ----
  #include "log.h"
  #define NAME	"DeleGate"
! #define VERSION	"9.2.3-pre9y"
! #define DATE	"July 8, 2006"
  #define DSTATUS	"BETA"
  #define AUTHOR	"Yutaka Sato"
  #define A_ORG	"National Institute of Advanced Industrial Science and Technology"

  admin search upper oldest olders older1 this newer1 newers latest
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]