On Wednesday, January 9, 2019 at 5:12:09 PM UTC-8, Василий Колесников wrote:
>
> Hi all! Thanks for the great software!
>
> I came across a strange behavior: when I use `preconnect: :concurently` 
> option for connection then `server_logging` extension doesn't work.
>
> Here is an example:
>
> # frozen_string_literal: true
>
>
> require 'bundler/inline'
>
>
> gemfile(true) do
>   gem 'mysql2'
>   gem 'sequel'
> end
>
>
> require 'logger'
> require 'sequel'
>
>
> DATABASE_URL = URI('mysql2://[email protected]:3306/sequel_test')
> LOGGER = Logger.new(STDOUT)
> LOGGER.level = 0
>
>
> DB = Sequel.connect(
>   DATABASE_URL.to_s,
>   servers: {
>     read_only: {
>       host: DATABASE_URL.host,
>       port: DATABASE_URL.port
>     }
>   },
>   extensions: %i[
>     error_sql
>     server_block
>     server_logging
>     connection_validator
>   ],
>   loggers: LOGGER,
>   log_connection_info: true,
>   preconnect: :concurrently,
>   max_connections: 10
> )
>
>
> DB.with_server(:default) do
>   DB[:users].count
> end
>
>
Thank you for the report.  This issue occurs because preconnect does the 
connecting before loading extensions.  In order to allow server_logging to 
work with preconnect, we would have to preconnect after loading extensions, 
and that change could potentially cause backwards compatibility issues (not 
sure which ones, but it's not a change I would make outside of a major 
version bump).

To keep backwards compatibility, we would have to introduce an additional 
option.  For lack of a better idea, let's call this 
preconnect_after_extensions.  Can you test the following diff and see if it 
works for you:

diff --git a/lib/sequel/database/misc.rb b/lib/sequel/database/misc.rb
index fa7b6e669..c670edd5d 100644
--- a/lib/sequel/database/misc.rb
+++ b/lib/sequel/database/misc.rb
@@ -148,8 +148,12 @@ module Sequel
       end
       Sequel::Database.run_after_initialize(self)
       if typecast_value_boolean(@opts[:preconnect]) && 
@pool.respond_to?(:preconnect, true)
+        preconnect = true
         concurrent = typecast_value_string(@opts[:preconnect]) == 
"concurrently"
-        @pool.send(:preconnect, concurrent)
+        unless typecast_value_boolean(@opts[:preconnect_after_extensions])
+          preconnect = false
+          @pool.send(:preconnect, concurrent)
+        end
       end
 
       case exts = @opts[:extensions]
@@ -164,6 +168,10 @@ module Sequel
       else
         raise Error, "unsupported Database :extensions option: 
#{@opts[:extensions].inspect}"
       end
+
+      if preconnect
+        @pool.send(:preconnect, concurrent)
+      end
     end
 
     # Freeze internal data structures for the Database instance.

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