Subject: bug#14333: 24.3.50; Emacs hangs when trying to exit

From: Eli Zaretskii <[email-masked]>
Date: Thu, 16 May 2013 10:35:04 +0300

> Date: Thu, 16 May 2013 09:18:16 +0200
> From: Dani Moncayo <[email-masked]>
> Cc: [email-masked]
> 
> > Grepping through Lisp files, it looks like these features are the ones
> > that use server sockets which could be involved in this issue:
> >
> >   Emacs server (server.el)
> >   ERC
> >   Gnus
> >   Tramp (unlikely, since it only uses server connections for some rare cases)
> >   org-irc.el
> >
> > If you use any of these, they are the potential culprits.
> 
> Of those, the only feature I think I use is Emacs server, because I
> have `(server-start)' in my init file.

That's what I thought.  So, if you start "emacs -Q" and then manually
start the server, does Emacs hang when exiting right after that?

> And FWIW, the hanged session I reported yesterday didn't have any
> client session connected to that server session (I rarely start client
> sessions).

That's expected, because this code near the place where the main
thread was stuck:

  if (winsock_lib != NULL && winsock_inuse == 0)
    {
      /* Not sure what would cause WSAENETDOWN, or even if it can happen
	 after WSAStartup returns successfully, but it seems reasonable
	 to allow unloading winsock anyway in that case. */
      if (pfn_WSACleanup () == 0 ||
	  pfn_WSAGetLastError () == WSAENETDOWN)
	{

clearly shows that winsock_inuse must be zero, which means we already
closed all the socket connections.  The question is, why the reader
thread of one of these connections is still waiting?