glacasa / Mastonet

C# Library for Mastodon
MIT License
225 stars 37 forks source link

Streaming Connection Reset Exception #123

Closed vantubbe closed 5 months ago

vantubbe commented 5 months ago

When calling timelineStream.Start(); I immediately get a connection reset exception here:

await socket.ConnectAsync(new Uri(url), CancellationToken.None); -> TimelineWebSocketStreaming.cs

I don't think this is an issue with Mastonet but I'm having a hard time figuring out what the root cause is. Oddly, sometimes it works and starts streaming, but usually I get the exception. Any chance the code below is improperly setting up the stream?

My code to reproduce is:

//create app and get access token
AuthenticationClient authClient = new AuthenticationClient("mastodon.social");
AppRegistration appRegistration = await authClient.CreateApp("sample app", null, null, GranularScope.Read);
AuthenticationClient authClient = new AuthenticationClient(appRegistration);
Auth authResult = await authClient.ConnectWithPassword(_email, _password);
//start stream
var _client = new MastodonClient"mastodon.social", authResult.AccessToken);
var _timelineStream = _client.GetPublicStreaming();
_timelineStream.OnUpdate += Streaming_OnUpdate;
_timelineStreamTask = _timelineStream.Start();
vantubbe commented 5 months ago

Was not an issue with Mastonet. It looks like servers can max out on the number of websocket streams they can serve simultaneously. In which case you get the above error when you start streaming.

If you retry every minute or so you'll usually get connected within a few minutes.