The problem is a socket binding error "address already in use".
Code: Select all
System.Net.Sockets.SocketException: Unknown error (0x2740)
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
Furthermore the problem is very strange because it only happens, and it always happen, in the following circumstance (on WINE).
- My program A.exe listens successfully on the server socket <anyip>:<port>.
- Then it start the program B.exe and close itself (closing the socket too).
- Program B.exe do something and then starts again A.exe.
- A.exe try to bind the server socket but in that case it fails with the error
"address already in use". - Restart A.exe, now the binding success.
Code: Select all
// This is only a generic example
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd",
Arguments = "/c /usr/bin/bash -c \"/usr/bin/sleep 5 && /usr/bin/wine path/of/process/program.exe\"",
UseShellExecute = false,
WorkingDirectory = "the/working/dir",
}
}
- LISTEN
- not listed due to socket is closed
- not listed due to socket is closed
- not listed due to socket is closed <- But I have got the error
- LISTEN
I've found that if I don't relaunch A.exe from B, but do it manually, everything works fine.
I also noticed this behavior that I wasn't expecting:
- if I use socket.Accept the socket is bound to the A.exe process,
- if I use socket.BeginAccept the socket is bound to the winserver32 process
Is there a known problem with freeing sock resources if you create a process startup chain?
Clearly if I simply close the A.exe application and restart it, none of this happens.