Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

New Post: When starting user stream and network is unavailable, stream continuously raises Started and Stopped Events.

$
0
0
Hi,

So I've done some further investigation. It turns out that the repeated events are due to my retry logic that's described below. However I feel that there is still some unexpected behavior.

What I'm trying to do is simulate the internet connection going down my machine. If internet is down while I'm starting the stream I get a WebException on the token.ExceptionHandler, this is fine. However if the stream is successfully setup and the internet goes down (manually pulling the network cable) I would have expected a stream stopped. This doesn't happen right away, usually takes 5-10 minutes which is also fine. The stopped event is raise with:

Stopped, System.Net.WebException: The operation has timed out.
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadLine()
at Streaminvi.Helpers.StreamResultGenerator.StartStream(Func2 processObject, Func1 generateWebRequest) in c:\Users\timart\Documents\My Box Files\Development\Tweetinvi\Release\Streaminvi\Helpers\StreamResultGenerator.cs:line 98

Now at this point I want to try to restart my stream and so I start the stream again (in the stopped event handler). The stream almost immediately fires another stopped event with:

Stopped, System.NullReferenceException: Object reference not set to an instance of an object.
at Streaminvi.Helpers.StreamResultGenerator.StartStream(Func2 processObject, Func1 generateWebRequest) in c:\Users\timart\Documents\My Box Files\Development\Tweetinvi\Release\Streaminvi\Helpers\StreamResultGenerator.cs:line 98

What I would expect is that on lost connection the stream is stopped. After which I can try to start the stream. The stream shouldn't raise started unless it is actually started.

Tweetinvi Version 0.8.3.23
Steps to Reproduce:
  1. Start the console app with internet connection
  2. Disconnect from internet
  3. Wait 5-10 minutes, stopped event will fire
  4. App will try to start stream once it's stopped, will receive StreamStarted followed by StreamStopped causing this step to be run in a loop
Console App:

class Program
{
private static IUserStream userStream;

static void Main(string[] args)
{

    string AccessToken = "AccessToken";
    string AccessTokenSecret = "AccessTokenSecret";
    string ConsumerKey = "ConsumerKey";
    string ConsumerKeySecret = "ConsumerKeySecret";

    var token = new Token(AccessToken, AccessTokenSecret, ConsumerKey, ConsumerKeySecret);
    token.ExceptionHandler += WebExceptionHandler;

    userStream = new UserStream(token);
    userStream.StreamStarted += us_StreamStarted;
    userStream.StreamStopped += us_StreamStopped;

    Task.Factory.StartNew(userStream.StartStream);
    Console.ReadLine();
}

private static void WebExceptionHandler(WebException webException)
{
    Debug.WriteLine("WebException, {0}", webException);
}

static void us_StreamStopped(object sender, TweetinCore.Events.GenericEventArgs<Exception> e)
{
    Debug.WriteLine("Stopped, {0}", e.Value);
    // Connection Lost Restart
    userStream.StartStream();
}

static void us_StreamStarted(object sender, EventArgs e)
{
    Debug.WriteLine("Started, {0}", e);
}
}

Let me know if anything is unclear,
Thanks,

Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>