braverhealth / phoenix-socket-dart

Cross-platform and stream-based implementation of Phoenix Sockets
https://pub.dev/packages/phoenix_socket
BSD 3-Clause "New" or "Revised" License
74 stars 37 forks source link

Infinite loop on channel close with 0.4.9 #18

Closed hworld closed 3 years ago

hworld commented 3 years ago

Seems like the channel leaving is triggering a loop to happen. I don't fully know how the code works, but looking at leave() in channel.dart has this code:

final onClose = (PushResponse reply) {
        _onClose(reply);
        close();
        leavePush.trigger(PushResponse(status: 'ok'));
      };
      leavePush
        ..onReply('ok', onClose)
        ..onReply('timeout', onClose)
        ..send();

It looks like we're pushing the 'ok' event onto the leavePush, which has an onReply handler for 'ok' to call onClose, which pushes the 'ok' reply, etc.

I noticed this because I have logging set to Level.ALL and it just outputted thousands of log messages until eventually:

I/flutter (20691): [phoenix_socket.channel.room_2] FINER 2020-12-21 11:33:57.616621: Leave message has completed
I/flutter (20691): [phoenix_socket.push.room_2] FINER 2020-12-21 11:33:57.616648: Triggering 1 callbacks
E/flutter (20691): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Stack Overflow
matehat commented 3 years ago

On it!

matehat commented 3 years ago

@hworld fix is published as 0.4.10. Thanks for reporting!!

hworld commented 3 years ago

Dang, thanks so much for the quick turnaround!

matehat commented 3 years ago

It helps that we use it in production 😄