I have a script that deletes resources and creates new ones. Every now and then it times out and I can't figure out why. It seems to happen when I run the script multiple times, but I couldn't get a definite pattern. I found that my server hasn't picked up the message yet since there's no logging for the request yet.
$old_values = Invoke-RestMethod -Uri $uri -Method Get
foreach($old_value in $old_values.result) {
Invoke-RestMethod -Uri "$uri&key=$old_value.id" -Method Delete
}
$new_value = Invoke-RestMethod -Uri "$uri" -Body "{}" -ContentType application/json -Method Post
Interesting note, I get occasional timeouts when I run the Invoke-RestMethod calls directly from powershell. I also ran them with Fiddler and never got timeouts.
[Edit] I've been checking the connections with netstat. While the commands are hanging, they're listed as ESTABLISHED. But I keep seeing TIME_WAIT connections listed to my server. Is there a chance my connections aren't getting closed?
The link David Brabant posted above contains this workaround that solved the problem for me:
$r = (Invoke-WebRequest -Uri $uri `
-Method 'POST' `
-ContentType 'application/json' `
-Body '{}' `
).Content | ConvertFrom-Json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With