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

What's the best way to close open connections on forking? #183

Closed
zedtux opened this issue May 16, 2023 · 5 comments
Closed

What's the best way to close open connections on forking? #183

zedtux opened this issue May 16, 2023 · 5 comments

Comments

@zedtux
Copy link

zedtux commented May 16, 2023

Tell us about your environment

Ruby version: 3.0.4

Rails version: 6.1

anycable gem version: 1.3.0

anycable-rails gem version: 1.3.7

grpc gem version: 1.54.0

What did you do?

I am migrating my app from running ActionCable with Puma to AnyCable. I have the following code in my Puma config file:

# frozen_string_literal: true

# Based on https://www.mongodb.com/docs/mongoid/7.5/reference/configuration/#puma
on_worker_boot do

  Mongoid::Clients.clients.each do |name, client|
    client.close
    client.reconnect
  end
end

# Based on https://www.mongodb.com/docs/mongoid/7.5/reference/configuration/#puma
before_fork do
  Mongoid.disconnect_clients
end

# ...

Which closes open connections to MongoDB on forking (see the MongoDB documentation link for more details).

My questions are:

  • Do I have to do the same with AnyCable?
  • Is there the same kind of hooks I could use to perform the same task if it's required?

Thanks for AnyCable !!

@Envek
Copy link
Member

Envek commented May 16, 2023

No, you don't need to do the same for AnyCable, as there is no forking or child process spawning in AnyCable RPC part as far as I know. Refer to AnyCable architecture for details.

@palkan
Copy link
Member

palkan commented May 17, 2023

Yep, @Envek is correct. AnyCable RPC server uses a single process, no forking. So, no special attention is required.

@palkan palkan closed this as completed May 17, 2023
@zedtux
Copy link
Author

zedtux commented May 17, 2023

Thank you both for your input 👌

@Envek
Copy link
Member

Envek commented May 18, 2023

@palkan, I'm curious about Embedded mode though. What happens when AnyCable RPC is embedded into clustered Puma for example? Does it stay in master process? 🤔

@palkan
Copy link
Member

palkan commented May 18, 2023

That's a good question.

Does it stay in master process?

Yeah, I think it should, but only if we preload the app.

In a clustered Puma setup, I run an RPC server within a single worker process. Here is an example: https://github.com/anycable/anycable-twilio-hanami-demo/blob/35aa3ad6dbcb47420a0b9c86af1a0290b242675d/kaisen/config/puma.rb#L17-L26

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

No branches or pull requests

3 participants