Windows PowerShell Home
TCP connection hanging in CLOSE_WAIT when using Invoke-RestMethod with PUT or DELETE
3/19/2014 7:05:50 AM
User(s) can reproduce this bug
When issuing more than two Invoke-RestMethod commands with the PUT or DELETE method against the same server, the third one fails with error: "Invoke-RestMethod : The operation has timed out." Only after closing the powershell and reopening will allow a new Invoke-RestMethod command run successfully.
This behavior was tested with two different servers, offering a REST API. GET and POST methods are not affected.
Using "netstat -an" you will see for the server communicating with, two active connections with state CLOSE_WAIT. On the server side you will see FIN_WAIT_2.
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.
How often does this happen?
Have you seen this problem before in this product?
Yes, this happens in all previous versions
Issue three Invoke-RestMethod commands with PUT or DELETE method against the same server from the same powershell in a row.
Either should powershell issue a close() and send a "FIN,ACK" in response to the server's "FIN,ACK" or the tcp session should be reused if possible.
to post a comment.
Please enter a comment.
to post a workaround.
Please enter a workaround.
on 3/19/2014 at 8:53 AM
using Invoke-WebRequest instead of Invoke-RestMethod does work:
(Invoke-WebRequest -Uri $uri -Method DELETE -Headers $headers).content | ConvertFrom-Json
© 2014 Microsoft