On Friday, October 21, 2016 at 6:56:40 AM UTC-7, Jannis Hübl wrote:
>
> Hello,
>
> we are using sequel to connect to different databases using the 
> DB#with_server method. While we are in the block every time we are doing a 
> database query sequel creates a new connection to the database.
> This is because every connection is disconnected in the release method of 
> Sequel::ArbitraryServers, if a server is passed as Hash like it is in our 
> case. Also the connection is deleted from the cache.
>
>     # If server is a hash, delete the thread from the allocated
>     # connections for that server.  Additionally, if this was the last 
> thread
>     # using that server, delete the server from the @allocated hash.
>     def release(thread, conn, server)
>       if server.is_a?(Hash)
>         a = @allocated[thread]
>         a.delete(server)
>         @allocated.delete(thread) if a.empty?
>         disconnect_connection(conn)
>       else  
>         super
>       end
>     end
>
> Is there a workaround to keep the connection? Or is this a bug?
>

Currently, no there isn't a way to keep the connection, and this is 
expected behavior, not a bug.  If you use arbitrary servers, Sequel creates 
a new connection for each block, and disconnects at the end.  Sequel does 
this because otherwise the connections would leak.  If you plan to connect 
to the same servers on a regular basis, I would use real shards in the 
:servers option when creating the Database object.

I suppose as a new feature, I would consider an option to cache the 
connection, via some key present in the connection options hash.  The user 
would then be responsible for any connection leaks generated if they chose 
to use the feature.

Thanks,
Jeremy

-- 
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