Fixing WSAETOOMANYREFS (0x0000274B) on Windows Server
This error means Windows ran out of kernel object references, usually from too many open sockets or handles. The quick fix is closing unused apps or rebooting, but the real fix is adjusting the TCP/IP parameter.
Quick answer: Reboot the machine to clear stuck handles, then check for handle leaks using !htrace in WinDbg. If that doesn't cut it, increase the kernel object limit via registry.
What's actually happening here
You're seeing 0x0000274B (WSAETOOMANYREFS) when your app tries to create a socket or bind to a port. This isn't a port exhaustion issue — it's a kernel object reference counter hitting its cap. Windows keeps a count of open references to certain kernel objects like sockets, file handles, or threads. When that count hits 16,384 (the default limit), Windows says "no more."
I've seen this most often on Exchange servers running 2016 or 2019, especially after a backup job goes sideways and leaves orphaned connections. Also happens on IIS servers with high concurrent user loads where the app pool doesn't recycle cleanly.
Fix steps (try in order)
- Reboot the server. Yeah, boring, but it works. If the error goes away after reboot, you've got a leak somewhere. Start tracking down the culprit.
- Check handle counts. Open Task Manager, go to the "Details" tab, add the "Handles" column. Sort descending. Look for any process with more than 5000 handles. That's your leak.
- Use netsh to check TCP settings. Run this command in an elevated command prompt:
Look for "TCP Chimney Offload" — if it's enabled, disable it. That feature causes more problems than it solves.netsh int tcp show globalnetsh int tcp set global chimney=disabled - Increase the kernel object limit. This is the real fix for servers that legitimately need more references. Open regedit, go to:
Create a DWORD calledHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\ParametersTcpMaxDataRetransmissionswith a value of 10 (decimal). Then create another DWORDMaxUserPortwith a value of 65534 (decimal). Reboot after changing these. - Check for handle leaks in code. If you control the application, use WinDbg or Process Monitor to trace handle creation and closure. Look for
CreateFileorWSASocketcalls without matchingCloseHandleorclosesocket.
Alternative fixes if the main ones fail
If you've rebooted, checked handles, and still see the error:
- Disable Windows Filtering Platform (WFP). Third-party firewalls or antivirus can peg the reference counter. Temporarily disable the service (it's
BFEin services.msc) and see if the error stops. If yes, blame your security vendor. - Increase the
IRPStackSizeregistry value. Go toHKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parametersand setIRPStackSizeto 20 (decimal). This allocates more buffer space for I/O request packets. - Check for port exhaustion anyway. Even though the error isn't about ports, sometimes it masks itself. Run:
If you see thousands of TIME_WAIT connections, reduce thenetstat -an | find ":80" | find "TIME_WAIT"TcpTimedWaitDelayfrom 240 to 30 seconds via registry.
Prevention tips
- Monitor handle counts daily. Set up a perfmon counter for
Process\Handle Countper process. Alert if any process goes over 3000 handles. - Use connection pooling in your apps. Don't open/close sockets per request. That's amateur hour.
- Keep Windows updated. Several patches between 2020 and 2023 fixed kernel object reference bugs. At minimum, be on Windows Server 2019 with KB5005112 or later.
- Set a scheduled task to restart leaky services. If you can't fix the code, restart the service nightly at 3 AM. Not elegant, but it works.
Bottom line: 0x0000274B is your system saying "I'm full." Listen to it. Reboot first, then dig into handle counts. The registry tweaks above have saved my ass dozens of times on Exchange and IIS boxes.
Was this solution helpful?