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

Implemented ping support for Celluloid and EventMachine. #236

Merged
merged 6 commits into from
Dec 22, 2018

Conversation

dblock
Copy link
Collaborator

@dblock dblock commented Oct 31, 2018

Closes #223

@RodneyU215 Want to code review this?

@RodneyU215
Copy link
Collaborator

Celluloid and EventMachine need to ensure that the timers are canceled on disconnect. This prevents the connection from being reestablished when the user intentionally closes it. This was achieved for async-websocket by surfacing the #cancel method on @timers:

module Slack
  module RealTime
    module Concurrency
      module Async
        class Reactor < ::Async::Reactor
          def_delegators :@timers, :cancel
        end

        class Socket < Slack::RealTime::Socket
          def disconnect!
            super
            @reactor.cancel
          end
        end
      end
    end
  end
end

@RodneyU215
Copy link
Collaborator

We also have to implement a #restart! method for both Celluloid and EventMachine. This method is responsible for updating web socket url to the new one and kicking off the run_loop again. Here's initial approach we took in async-websocket. Note: there's going to be a snag around how client is passed.

module Slack
  module RealTime
    module Concurrency
      module Async
        class Socket < Slack::RealTime::Socket
          def restart_async(client, new_url)
            @url = new_url
            @last_message_at = current_time
            return unless @reactor
            @reactor.async do
              client.run_loop
            end
          end
        end
      end
    end
  end
end

@dblock
Copy link
Collaborator Author

dblock commented Nov 1, 2018

Made some progress, but definitely could use help with the other TODOs, especially with proper tests that fail in Celluloid/EM and pass in async rn.

@dblock
Copy link
Collaborator Author

dblock commented Dec 10, 2018

@RodneyU215 if you want to help with this one, that'd be greatly appreciated, I won't have time for it for a while

@RodneyU215
Copy link
Collaborator

Thanks for the nudge! I'll work on it this week.

Rodney Urquhart added 2 commits December 15, 2018 04:46
…so that EventMachine continues running until disconnect! is called.
@RodneyU215
Copy link
Collaborator

Celluloid and EventMachine need to ensure that the timers are canceled on disconnect.

I tested this for EventMachine (via faye-websocket) and all timers are canceled when EventMachine.stop is called. I've not been able to find a comparable method in Celluloid however. Instead Celluloid continues to have an issue where the Actor crashes even after the main thread has been closed.

We also have to implement a #restart! method for both Celluloid and EventMachine.

I've implemented the #restart! method for EventMachine. You can find that PR here. I've not had much success with Celluloid, but can make another attempt in a few days.

Side note: celluloid-io appears to be unmaintained do we still want to continue to support it?

Implementing restart_async for EventMachine
@dblock
Copy link
Collaborator Author

dblock commented Dec 16, 2018

@RodneyU215 I think we should at least try supporting celluloid. While unmaintained there's a slew of bots out there using it, including my own :)

I am going to merge this on green. How do I reproduce the problem with Celluloid?

@dblock dblock merged commit 407fd9f into slack-ruby:master Dec 22, 2018
@dblock
Copy link
Collaborator Author

dblock commented Dec 22, 2018

I merged this. Let's move from here.

@RodneyU215
Copy link
Collaborator

@dblock Thanks for moving things forward. The issue with Celluloid surfaced by just running the integration tests. Starting tomorrow I'll have some free time over the next couple weeks to dig deeper into that issue.

@dblock dblock deleted the em-celluloid-ping branch December 27, 2018 15:55
@dblock
Copy link
Collaborator Author

dblock commented Jan 8, 2019

@RodneyU215 Could really use some help here so we can get the next release out, haven't had much time to deal with Celluloid and EM, but would be happy to test on some production bots. Integration tests seem to pass, so...

@RodneyU215
Copy link
Collaborator

@dblock I believe EM is stable; I'm still working on verifying that Celluloid works as expected. I'm glad to hear that the integration tests are passing. This leads me to believe that it's likely an issue for me locally.

I've got a few other things to get through at work before Friday but I'll continue working on it this weekend and follow up by Monday.

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