FUTURE POSTS
- Partial writes, IO_Uring and safety - about one day from now
- Configuration values & Escape hatches - 5 days from now
- What happens when a sparse file allocation fails? - 7 days from now
- NTFS has an emergency stash of disk space - 9 days from now
- Challenge: Giving file system developer ulcer - 12 days from now
And 4 more posts are pending...
There are posts all the way to Feb 17, 2025
Comments
Race condition between creating the TcpListener and starting it and multiple threads calling this code at the same time.
Solution: lock around new TcpListener and tcpListener.Start().
RAGE... I hate when people do find available port by iterating and catching exceptions. The correct way to do this is:
listener = new TcpListener(IPAddress.Loopback, 0); //
RTFMMSDN listener.Start(); port = ((IPEndPoint)listener.LocalEndpoint).Port;Let the OS do it's work.
@hazzik wow, goes to say that sometimes RTFM is the best answer :-).
Try run this code: https://gist.github.com/hazzik/edd28a7129f820b4579b
How many exceptions!?! Zero.
I got six exception when I ran it with Linqpad
An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full [Source = Worker Thread]
Giorgi they are all unrelated to the problem, it is just because it tries to spawn 1000 threads
@hazzik the nuance is that the proxy is trying to create a listener within a known range: 1 - port AFAIK, you do not have this when using 0 as a port
Signature of the constructor is different between stack and code. You're running old code?
You have another constructor ProxyServer(int port, int to) that do not catch SocketException?
As Jahmai points out the stacktrace shows ProxyServer..ctor(Int32 from, Int32 to) and not ProxyServer..ctor(Int32& from, Int32 to).
Jahmai, DING DING DING, yes, that is the issue
Comment preview