Thread overview
[Issue 4344] New: Sockets with multiple threads report missing/failed WSAStartup
Jun 19, 2010
Adrian Matoga
Jul 11, 2010
godmyoh
Aug 10, 2010
Rainer Schuetze
Oct 31, 2010
Stephan Dilly
June 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4344

           Summary: Sockets with multiple threads report missing/failed
                    WSAStartup
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: epi@atari8.info


--- Comment #0 from Adrian Matoga <epi@atari8.info> 2010-06-18 21:02:30 PDT ---
Created an attachment (id=666)
source for server and client to reproduce this issue

Hello,

I encountered a strange problem dealing with sockets and threads under Windows
(I use 64-bit 7 Pro).
The server socket successfully accepts a connection and passes obtained socket
to newly created thread, which deals with it correctly.
However, the server socket then breaks with the exception on any next
operation.
The SocketException.errorCode is always 10093, which stands for missing or
failed WSAStartup. Indeed, when I place WSAStartup after accepting connection,
it works well (but most probably needs matching WSACleanup() call).
The single-threaded version also presents no problems.
I tried with DMD 2.046 and 2.047 with same result.
I attach example sources of both server and client showing the issue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 11, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4344


godmyoh <menodinulla@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |menodinulla@gmail.com


--- Comment #1 from godmyoh <menodinulla@gmail.com> 2010-07-10 21:17:09 PDT ---
I also encountered same problem on Winsows XP.

Sample:
----------------------------------------------------
import core.thread;
import std.socket;

void main()
{
    auto thread = new Thread({});
    thread.start();
    thread.join();

    auto socket = new TcpSocket;
}
----------------------------------------------------

Results:
----------------------------------------------------
std.socket.SocketException: Unable to create socket
----------------------------------------------------

And I found following code in /trunk/phobos/std/socket.d.

193 static ~this() 194 { 195     version(Win32) 196     { 197         WSACleanup(); 198     } 199 } 200

I think that "shared static ~this()" is correct.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 10, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4344


Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario@gmx.de


--- Comment #2 from Rainer Schuetze <r.sagitario@gmx.de> 2010-08-10 01:34:13 PDT ---
After several hours of debugging I found the problem with the non-shared destructor aswell.

"shared static ~this" seems to do the trick for now, but when building a DLL, unloading it will also kill connections of the whole application. I'd say the calls to WSAStartup and WSACleanup should be explicite.

Fortunately, in my case, the DLL is never unloaded...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4344


Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |schveiguy@yahoo.com
         Resolution|                            |FIXED


--- Comment #3 from Steven Schveighoffer <schveiguy@yahoo.com> 2010-10-19 06:18:55 PDT ---
Fixed in changeset http://www.dsource.org/projects/phobos/changeset/2107

This does not fix the DLL issue, but phobos is not DLL friendly anyways.  If you wish, open a separate issue for that.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 31, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4344


Stephan Dilly <spam@extrawurst.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b599400@lhsdv.com


--- Comment #4 from Stephan Dilly <spam@extrawurst.org> 2010-10-30 18:08:34 PDT ---
*** Issue 4975 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 08, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4344


Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |debio264@gmail.com


--- Comment #5 from Steven Schveighoffer <schveiguy@yahoo.com> 2010-11-08 05:18:37 PST ---
*** Issue 5183 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------