linvi / tweetinvi

Tweetinvi, an intuitive Twitter C# library for the REST and Stream API. It supports .NET, .NETCore, UAP (Xamarin)...
MIT License
1k stars 220 forks source link

Random timeout on Linux when Tweetinvi makes a REST request #700

Open MayakoAelys opened 6 years ago

MayakoAelys commented 6 years ago

Server Environment:

Dev environment (laptop)

I'm making a little ASP.Net Core project that will let me do some operations on my twitter account. I never got a timeout while developing on my laptop but when I launch my project on my VPS (Debian 8), I sometimes get a timeout error.

My firewall doesn't block the port and the ping is fine:

--- api.twitter.com ping statistics ---
174 packets transmitted, 174 received, 0% packet loss, time 173274ms
rtt min/avg/max/mdev = 3.269/3.440/3.516/0.067 ms

I think this may be a bug related to .NET Core itself and not Tweetinvi (maybe with the HttpClient object?), or a deadlock somewhere, I have no idea honestly. Increasing the request timeout from 10s to 30s didn't help either.

Do you have any idea that would help me to investigate this issue?

MayakoAelys commented 6 years ago

I got this timeout error when I started an authentification request and also when I wanted to block an user.

It can block more than 1000 accounts in one streak but struggle to block 10 accounts just after that. It's really random... And not related to a rate limit that I would have reach.

linvi commented 6 years ago

Hello,

Thank you for your feedback. I have never experienced such a behaviour in the past. From your description though I can notice that you are blocking a lot of users in a very short amount of time.

Even though it is probably not related, be careful as your app will probably be reaching a limit set by Twitter as per the "fair usage" of the API. If you want to perform such type of operation on a large scale you will have to do them by way smaller batches over a day or 2.

Twitter will otherwise consider your app behaviour as suspicious and limit it or potentially ban it.

As per the timeout, I am not sure, if you can find a pattern please share it here, so that I can try to have a look at it as soon as I can find some free time.

Cheers, Linvi

MayakoAelys commented 6 years ago

Hi again @linvi

I did more searches and ended with a little benchmark tool (very primitive) to compare your requests delay with my custom OAuth implementation written from scratch (with no dependencies, only using HttpClient) and found something interesting

image One failed request with tweetinvi = 10 seconds timeout exceeded

You can see that when I'm on Windows, both Tweetinvi and my custom imp. work fine. When I executed the same benchmark on my Debian server, Tweetinvi failed to send 27 requests and my custom implementation got the same issue since we can see that the maximum delay was 34487ms.

I think something is wrong on the .NET Core Linux implementation.

We can also see that Tweetinvi makes much longer to send and retrieve a request than my custom implementation. Even if I have hardcoded some values, I think that Tweetinvi can be optimized in some ways, but it's not the main issue here anyway, just a side note.

It's really not interesting (as I hardcoded a LOT of values) but if you want to see how I implemented my test request, I can paste the code here.

Thanks again for your awesome lib!

linvi commented 6 years ago

Thank you for this great feedback. If you can paste your code here, it can be useful for me to see if I can improve anything.

As per the problem it might be worth sharing this with the .NETCore team.

Thanks for getting back on this issue and I might in the future use a Debian for testing as for now most of the testing are being done on Windows 10, MacOS, iOS, Android and RaspberryPi 3.

MayakoAelys commented 6 years ago

I just pushed my (cleaned) test code here: https://github.com/MayakoLyyn/Benchmark-DotNetCore-Tweetinvi-HttpClient

If you can reproduce this, I agree that it would be a great idea to open an issue on the .NET Core repository 🙂