Skip to content

Commit

Permalink
Connection status check is protected when nil
Browse files Browse the repository at this point in the history
  • Loading branch information
sbellware committed Jan 18, 2019
1 parent adbd711 commit c707e7c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/message_store/postgres/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ def self.build_connection(instance)
end

def connected?
!connection.nil? && connection.status == PG::CONNECTION_OK
return false if connection.nil?

status = PG::CONNECTION_OK
begin
status = connection.status
rescue PG::ConnectionBad
status = nil
end

status == PG::CONNECTION_OK
end
alias :open? :connected?

Expand Down

0 comments on commit c707e7c

Please sign in to comment.