Skip to content
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

Fix/detect connection outages #29

Merged
merged 4 commits into from
Mar 20, 2024
Merged

Conversation

bpolaszek
Copy link
Owner

@bpolaszek bpolaszek commented Mar 15, 2024

Replaces #28 in a safer/cleaner way, following advices from clue/reactphp-redis#142 (comment)

What it does:

  • When ping_interval is positive, immediately ping connection before $transport->subscribe() is invoked. Reduces the risk of starting the hub with a broken redis link
  • Listen to the unsubscribe event and trigger a hub crash so that its supervisor can handle its respawn. I initially thought that unsubscribe wouldn't be safe (like a subscriber just closing the connection) but it looks it would only be triggered in the case of a lost connection, since Freddie never calls $client->unsubscribe().

cc @misaert:

With both ping_interval enabled and that small addition, the EventSource was always able to recover its connection to the hub once Redis was back on again (during my tests). Can you please give this one a try?

Thanks @SimonFrings for the tip!

@bpolaszek
Copy link
Owner Author

Sh*t, tests broken, likely because of the immediate ping, I forgot to composer ci:check after adding this...
I'll have a look.

…sTransport` doesn't connect to Redis within the unit test
…ort` doesn't connect to Redis within the unit test
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (b0350eb) to head (c632f1a).

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #29   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       141       141           
===========================================
  Files             25        25           
  Lines            409       411    +2     
===========================================
+ Hits             409       411    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bpolaszek
Copy link
Owner Author

Tests fixed! 🎉

@misaert
Copy link
Collaborator

misaert commented Mar 20, 2024

Hi Ben,

It seems that unsubscribe works well, even without enabling the ping.

But I guess this PR deserves to be merged 💪

Thanks,

Mika

@bpolaszek bpolaszek merged commit 7104712 into main Mar 20, 2024
20 checks passed
@bpolaszek bpolaszek deleted the fix/detect-connection-outages branch March 20, 2024 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants