FUTURE POSTS
- Using AI agents in long-lived software projects - 41 minutes from now
- Expertise in the age of AI, or: Matt's Claude'll handle this - 2 days from now
- 15+ years of working with coding agents - 6 days from now
- Putting Claude up against our test suite - 8 days from now
- The GPU Is the New Bangalore - 10 days from now
And 1 more posts are pending...
There are posts all the way to May 05, 2026
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); //
RTFMMSDNlistener.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