https://bugs.winehq.org/show_bug.cgi?id=54413
--- Comment #2 from François Gouget fgouget@codeweavers.com --- Yes. It's as if sockets and handles are in separate namespaces and we sometimes get a collision. But if that were the case DuplicateHandle() should never work on sockets so that hypothesis makes no sense.
The Microsoft documentation does say one should not use DuplicateHandle() on sockets, mostly because "the duplicate handle may not be recognized by Winsock at the target process" which is not the issue here. It's strange how this seems to suggest DuplicateHandle() of sockets works but is unreliable. And more importantly it does not say why it would be unreliable.
The documentation also says "DuplicateHandle interferes with internal reference counting on the underlying (socket?) object". But I don't see how this could be the issue here.
It does suggest our test is doing something it shouldn't. But then testing corner cases is not not uncommon...