We have a Windows Service written in .NET that we use to "sync" data into SharePoint Online. What the service does is to update items in a particular SharePoint list every 30 minutes (configurable, but doesn't seem to be related to the problem.)
After the service has been running for a while without issue, sometimes 2 weeks, sometimes more, it fails to connect to SPO and from then on will fail every time it runs with the same error (the IP address of the SPO URL may change in the error but everything else is the same.)
When someone notices that the data in the list is stale, we restart the service and it works perfectly. Obviously we can institute workarounds such as emailing a server admin when we run into this error, or have a watchdog restart our service, but we would really prefer to fix the root cause.
The exception that we get is:
14/09/2017 00:00:06.61 Error SharePoint Online Validation (STGMModelStatusSettings) An error occurred accessing SharePoint Online and/or associated services. Exception: System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 188.8.131.52:443 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at Microsoft.SharePoint.Client.Idcrl.IdcrlAuth.DoPost(String url, String contentType, String body, Func`2 webExceptionHandler) at Microsoft.SharePoint.Client.Idcrl.IdcrlAuth.GetUserRealm(String login) at Microsoft.SharePoint.Client.Idcrl.IdcrlAuth.GetServiceToken(String username, String password, String serviceTarget, String servicePolicy) at Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.GetAuthenticationCookie(Uri url, String username, SecureString password, Boolean alwaysThrowOnFailure) at Microsoft.SharePoint.Client.SharePointOnlineCredentials.GetAuthenticationCookie(Uri url, Boolean refresh, Boolean alwaysThrowOnFailure) at Microsoft.SharePoint.Client.ClientRuntimeContext.SetupRequestCredential(ClientRuntimeContext context, HttpWebRequest request) at Microsoft.SharePoint.Client.SPWebRequestExecutor.GetRequestStream() at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate() at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest() at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() at WorkbenchService.SharePointOnline.SPODataSync.ValidateConfigurationForSTGMTasks(ClientContext& clientContext, Web& web, List& list) in C:\redacted\SPODataSync.cs:line 133
My first thought was some kind of leak but the
clientContext is disposed correctly even on exception and is newed up every time so I'm not sure that can be it.