While creating my Powershell framework for Isilon I’m quite confident that I found a bug in Powershell. The affected cmdlet is “Invoke-RestMethod” and the bug is still valid for version 3 and 4.
I also reported the bug on Microsoft Connect and it was reproduced by at least 2 independent people.
If you found this post because you are also facing this issue or if you are willing to reproduce the bug, please go to Microsoft Connect and vote the bug as important to be resolved!
Investigating the tcp communication with wireshark, I can see that the client receives the “ACK,FIN” but is probably not issuing a close() as there is no “ACK,FIN” send as a response by the client to the server.
If using Fiddler in between you will not encounter the timeout but see in netstat for each Invoke-RestMethod command run, a CLOSE_WAIT. In the http standard only two connections are allowed to the same server. Fiddler is modifying this to allow unlimited http connections to the same server.
When closing the powershell a “RST” is send to the server, discarding the tcp session in CLOSE_WAIT state.
Using Invoke-WebRequest instead of Invoke-RestMethod does work:
(Invoke-WebRequest -Uri $uri -Method DELETE -Headers $headers).content | ConvertFrom-Json