Skip to content

Reconnector will not be triggered when there is no onError parameter in the subscription processing #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Immanuel-Licht opened this issue Aug 1, 2019 · 5 comments

Comments

@Immanuel-Licht
Copy link

Immanuel-Licht commented Aug 1, 2019

Hi Elad,
I found the reconnector will not be triggered when there is no OnError parameter in the subscription process .

    public IWampRealmProxy Start(Dictionary<string, Action<IDictionary<string, ISerializedValue>>> subscribers)
    {
        var disposables = new List<IDisposable>();
        Reconnector = new WampChannelReconnector(_channel, async () =>
        {
            await _channel.Open().ConfigureAwait(false);
            disposables.ForEach(d => d.Dispose());
            disposables.Clear();
            foreach (var sub in subscribers)
            {
                var disposable = _channel.RealmProxy.Services.GetSubject(sub.Key).Subscribe(x =>
                 {
                     sub.Value?.Invoke(x.ArgumentsKeywords);
                 });
                disposables.Add(disposable);
            }
        });
        Reconnector.Start();
        return _channel.RealmProxy;
    }

I have to add OnError paramter in Subscribe method for the connector to run normally.

                var disposable = _channel.RealmProxy.Services.GetSubject(sub.Key).Subscribe(x =>
                 {
                     sub.Value?.Invoke(x.ArgumentsKeywords);
                 }, e =>
                 {
                     Console.WriteLine(e.ToString());
                 });

I think the reconnector should not be affected.
And it caused another problem, the reconnection will be triggered when I actively close the channel.So I have to dispose the reconnector when the channel is closed ,to avoid duplicate subscriptions.

    public async Task<GoodbyeMessage> Close(string reason = WampErrors.CloseNormal)
    {
        Reconnector.Dispose();
        return await _channel.Close(reason, new GoodbyeDetails());
    }

Is original design so or my code wrong?
Thanks

@darkl
Copy link
Member

darkl commented Aug 1, 2019

If I recall correctly, specifying no OnError handler should cause your program to crash. See #193. This is the behavior of System.Reactive.

In this case, the reconnecter mechanism makes no sense as the program has crashed.

@Immanuel-Licht
Copy link
Author

Thanks.
Subscription is normal without OnError handle, but can't reconnect.
By the way,maybe it's time to update the document.There should be some recommended code to ensure it is robust and reliable.

@darkl
Copy link
Member

darkl commented Aug 2, 2019 via email

@darkl
Copy link
Member

darkl commented Aug 2, 2019

Ok, this commit makes the System.WebSockets connection consistent with the WebSocket4Net connection, i.e. exceptions not handled by the user (such as the one you get if you don't subscribe to OnError) make their program crash. I'll release a new version to NuGet in the next following days.

Elad

@Immanuel-Licht
Copy link
Author

Well done,Elad.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants