rowland / fb

Firebird Extension Library for Ruby
64 stars 35 forks source link

Connection timeout #40

Closed rzane closed 9 years ago

rzane commented 9 years ago

As best I can tell, there is no timeout when establishing a connection. The following script ran for about 4 minutes on my machine:

#!/usr/bin/env ruby
require 'fb'

Fb::Database.new(
  database: 'fakeurl.com:/fake/database/path.fdb',
  username: 'sysdba',
  password: 'masterkey'
).connect

When it finally did exit, this was the error:

$  time ./connection_timeout.rb
./connection_timeout.rb:8:in `connect': Unsuccessful execution caused by a system error that precludes successful execution of subsequent statements (Fb::Error)
Unable to complete network request to host "fakeurl.com".
Failed to establish a connection.
    from ./connection_timeout.rb:8:in `<main>'
./connection_timeout.rb  0.07s user 0.02s system 0% cpu 4:16.76 total

The connection should probably bail after a certain amount of time. Ideally, this amount of time would be configurable in the connection hash. I'm not a C guy, so I'm not sure I'll be of any help.

rowland commented 9 years ago

The gem is a wrapper around fbclient, which does not have a timeout setting, to my knowledge. Nor do we have access to the socket used by fbclient or we could specify a timeout on the socket. Fortunately, in practice, this is rarely a problem. Most database connections are local and fail quickly if they are going to fail.

rzane commented 9 years ago

Okay. Thanks anyway.