W3C home > Mailing lists > Public > www-lib@w3.org > July to September 2000

Bug in HTTCP.c

From: Jens Meggers <jens@meggers.com>
Date: Fri, 7 Jul 2000 19:34:10 +0200
Message-ID: <005901bfe839$8f9d8bf0$6b02a8c0@pille>
To: <www-lib@w3.org>
Hi there,

I found a serious bug in HTTCP.c for Win32 systems.

In HTDoConnect(), the connect command is done before the WSAAsyncSelect() that is called when HTHost_register(host, net, HTEvent_CONNECT); is executed. Although that is in line with the WinSock2 and Microsoft documentation, it does _not_ work all the time. I have done extensive tests on Win2000 and Win 4.0 SP5. In very rare cases, the connect is finished between the connect() command itself and the WSAAsyncSelect(). In this unlikely case, WinSock does not (always) send the FD_CONNECT message. As a result, when using the Async mode, the event loop hangs because there is no timeout procedure registered for FD_CONNECT.

Thus, I moved the HTHost_register in front of the connect command in HTDoConnect():

case TCP_NEED_CONNECT:

#ifdef _WINSOCKAPI_
     HTHost_register(host, net, HTEvent_CONNECT);
#endif
     status = connect(HTChannel_socket(host->channel), (struct sockaddr *) &host->sock_addr,
        sizeof(host->sock_addr));

In Addition, I had to remove the same command in HTDoConnect() in case of WSA_WOULDBLOCK:

  if (NETCALL_WOULDBLOCK(socerrno))
  {
      HTTRACE(PROT_TRACE, "HTDoConnect. WOULD BLOCK `%s'\n" _ hostname);
#ifndef _WINSOCKAPI_
      HTHost_register(host, net, HTEvent_CONNECT);
#endif
   return HT_WOULD_BLOCK;
  }

After this change, I had never a hanging event loop again, even when looping for a few 1000 requests.

best regards,

Jens
Received on Friday, 7 July 2000 13:44:19 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 23 April 2007 18:18:37 GMT