I have a simple windows service (C#) that uses a timer to check an external API every 15 mins.
The service runs fine until the machine sleeps, then after a few more iterations (about 40 mins in) it loses internet and all Requests time-out. This behavior is reproducible across machines, accounts, etc. and doesn't recover until the service is restarted.
The odd thing, if we leave Fiddler running on the machine, this doesn't happen - the service will run for days with no issues.
We've tried running it under custom/admin accounts, NetworkService and LocalService accounts, allow the user to operate as OS, power-saving configs on the nic, trying multiple machines (7 and Server 08), port all code to a WinForms app - all with the same behavior.
I'm pulling hair out and hoping the "works with Fiddler" will raise eyebrows from someone in the know... My next test is to write a "controller service" that stops/restarts the first service but I hate that solution.
*updated, here's the code that makes API requests
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uriDomain + uriLogin);
WebResponse resp = req.GetResponse();
and downloads available files
using (WebClient client = new WebClient())
{
client.Headers["Cookie"] = persistCookie;
client.DownloadFile(uriDomain + fileName, localStoragePath + fileName);
}
The .net CLR should recycle connections - there's no explicit close, etc. for these objects. Further, I don't understand how running Fiddler causes everything to work fine.
thanks
Sounds like you're running out of connections.
A quick test would be to change the time from 15 minutes to 1 minute then repeat the test. If it fails faster, then there's a fair chance that the service isn't correctly closing connections. Eventually you'll hit the limit.