wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
335 stars 131 forks source link

Intermittent http client timeout #298

Closed bjh0 closed 2 years ago

bjh0 commented 2 years ago

I am experiencing an intermittent timeout of the http client which I am struggling to troubleshoot.

My website is a blazor server application deployed to an Ubuntu server. One of the pages of this website fetches blog posts from my wordpress instance.

When it's working, the posts are fetched without error and clicking on any post gets me the rendered post, also without error. This working status can continue for hours or days at a time.

After a period of time, and without making any changes to my server whatsoever, I encounter the error state. And in this state the posts are not retrieved and eventually I get a timeout exception:

Failed to load post: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.

After the error state has been in place for some time - some hours usually - the working state will eventually return, apparently of its own accord.

The working and not working states are unpredictable in nature, but they always occur in discrete blocks, i.e. when it's working it stays working for the full period and when it's not working it stays not working for the full period.

During the period where the WordPressPCL client is not working, I can run my website in development and it works perfectly - so I know there is no issue with the Wordpress instance. Also, from my deployed website, I have another service which uses a http client and this always works without fail. So as far as I can tell there is no issue with my deployed website or the server settings that would restrict outgoing http calls in some way. In between the working and not working states I typically make no intervention whatsoever. But if I do try an intervention, such as restarting my website or restarting apache, the working state is not achieved. It just does it all of its own accord.

So based on all of this I am really struggling to get to the bottom of the issue. Only the WordPressPCL client is affected, but I can't figure out why.

Any ideas would be very welcome.

bjh0 commented 2 years ago

I managed to solve this issue and it had nothing to do with the WordpressPCL client.

I monitored outgoing traffic using the following command: watch -n1 lsof -i TCP:80,443

Then, when I went to my website index page (which is the page that fetches the blog posts from wordpress using the client), I noticed that the outgoing call to my wordpress instance had the wrong IP address. The wordpress instance runs on the same server, so calls to the wordpress API should have the public IP address of my server.

It transpires that the server itself was configured with an incorrect public IP address. How was it ever working? Well, I think it uses a hierarchy to determine hostname IP addresses. It must have been using a public DNS when it was in the working state, but in the non-working state it was using the server's internal configuration.

Fixing the configuration solved the problem.