Hi!

First of all, thanks for a great gem with great documentation and great 
support! I recently sent a pull request which was merged with support for 
Oracle via ODBC. I use this to connect directly to our ERP system from a 
Ruby application. Now and then I started getting weird error messages from 
the ODBC Driver (unixODBC) and after a lot of investigation I came to the 
conclusion that the error message really was related to the read timeout 
being expired.

So I started digging into the implementation of the connection pool. The 
first thing I tried was to go single-threaded but that didn't solve the 
problem. Eventually I implemented my own connection pool which simply 
*always* closed the connection explicitly after having sent a query. This 
works but it feels awkward, especially since our ERP provider claims that 
it should be possible to send more than one query per session. The problem 
seem to be that the current implementation of the connection pool holds 
connection(s) but never understands when a connection is dead and just 
raises an exception. Is there something I'm missing here?

This is my connection pool which solves the problem:

class Sequel::SingleConnection < Sequel::ConnectionPool
  def initialize(db, opts=OPTS)
    super
    @conn = nil
  end

  # Disconnect the connection from the database.
  def disconnect(opts=nil)
    return unless @conn
    disconnect_connection(@conn)
    @conn = nil
    nil
  end

  # Yield the connection to the block.
  def hold(server=nil)
    begin
      yield (@conn ||= make_new(DEFAULT_SERVER))
      *disconnect*
    rescue Sequel::DatabaseDisconnectError, *@error_classes => e
      disconnect if disconnect_error?(e)
      raise
    end
  end

  def max_size
    1
  end

  def size
    @conn ? 1 : 0
  end

  private

  def preconnect(concurrent = nil)
    hold{}
  end
end

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to