Skip to content

Automatically manage known-common DB connections #135

@nevans

Description

@nevans

Specifically, check for defined? ActiveRecord::Base and Resque.redis. Then we can remove those bits from the necessary config for probably 95% of users (and remove one of the most common misconfigurations). Any other connections will still need to be managed manually (and we will still need to document this in the README).

We should do a quick search for open TCP sockets and issue a warning if any of them were shared from the master. e.g.

# helper
def open_tcp_sockets
  return [] if configured_to_ignore_open_socket_warnings?
  ObjectSpace.each_object(TCPSocket).each_with_object({}) do |f,h|
    fd = f.fileno rescue nil  
    h[fd] = f if fd && (!f.closed? rescue nil)
end

# immediately after fork
tcp_from_master = open_tcp_sockets

# after running the after fork hooks
current_open_tcp_fds = open_tcp_socket_fds.keys
(tcp_from_master.keys & current_open_tcp_fds).each do |fd|
  socket = tcp_from_master[fd]
  unless configured_to_ignore_warning_for?(socket)
    print_warning_for(socket)
  end
end

We could also extend this to open File, IO, UDPSocket, etc, but those are more likely to be legitimately shared between master/worker.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions