SSL Support?
davidplappert opened this issue · 13 comments
I am trying to use a PlanetScale database with my Ruby Lambda, and while I can run it locally and in docker, I get "SSL connection error: unknown error number" when running in Lambda.
require 'active_record'
require 'mysql2-lambda'
require 'mysql2'
ActiveRecord::Base.establish_connection(
adapter: 'mysql2',
database: 'xxx',
username: 'xxx',
host: 'xxx',
password: 'xxx,
sslverify: true,
# ssl_mode: :verify_identity,
# sslca: '/etc/ssl/cert.pem',
)
"errorMessage": "SSL connection error: unknown error number",
"errorType": "Function<ActiveRecord::ConnectionNotEstablished>",
"stackTrace": [
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:45:in `rescue in new_client'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:39:in `new_client'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:23:in `mysql2_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_handling.rb:327:in `retrieve_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_handling.rb:283:in `connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/model_schema.rb:553:in `load_schema!'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/attributes.rb:250:in `load_schema!'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/model_schema.rb:539:in `block in load_schema'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/model_schema.rb:536:in `synchronize'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/model_schema.rb:536:in `load_schema'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/model_schema.rb:392:in `columns_hash'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/query_methods.rb:1313:in `arel_column'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/calculations.rb:280:in `aggregate_column'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/calculations.rb:299:in `execute_simple_calculation'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/calculations.rb:269:in `perform_calculation'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/calculations.rb:144:in `calculate'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/calculations.rb:51:in `count'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/querying.rb:22:in `count'",
"/var/task/router.rb:8:in `router'"
]
Can you remove that extra require 'mysql2'
it should not be needed. Also, what Ruby version are you using? 2.5 or 2.7?
done, and 2.7
Would you mind doing a little research into what this means for the client side?
https://github.com/brianmario/mysql2#ssl-options
but only if your MySQL client library and server
have been compiled with SSL support.
Maybe we need some configure args for in our Dockerfile for the MySQL Connector?
@metaskills Looking into this from our side, curious to know if there's a reason for using this specific version of MySQL Connector, as it's quite dated.
Line 22 in e5748e8
Haven't confirmed yet if this is the reason, but wanted to check either way.
Hey @lizztheblizz, no reason that I can think of or remember. Maybe it was the only one I could find. Very open to changing/fixing that too.
This is still an issue.
SSL connection error: unknown error number
SSL connection error: unknown error number: ["/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/mysql2_adapter.rb:53:in rescue in new_client'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/mysql2_adapter.rb:43:in
new_client'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/mysql2_adapter.rb:23:in mysql2_connection'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in
public_send'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in new_connection'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in
checkout_new_connection'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:679:in try_to_checkout_new_connection'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:640:in
acquire_connection'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in checkout'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in
connection'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_handler.rb:211:in retrieve_connection'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_handling.rb:313:in
retrieve_connection'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_handling.rb:280:in connection'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/model_schema.rb:580:in
load_schema!'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/attributes.rb:264:in load_schema!'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/encryption/encryptable_record.rb:122:in
load_schema!'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/model_schema.rb:566:in block in load_schema'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/model_schema.rb:563:in
synchronize'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/model_schema.rb:563:in load_schema'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/model_schema.rb:429:in
attribute_types'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/model_schema.rb:455:in type_for_attribute'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/type_caster/map.rb:16:in
type_for_attribute'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/arel/table.rb:107:in type_for_attribute'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/table_metadata.rb:18:in
type'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/relation/predicate_builder.rb:59:in build'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/relation/predicate_builder.rb:54:in
[]'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/relation/predicate_builder.rb:126:in block in expand_from_hash'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/relation/predicate_builder.rb:79:in
each'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/relation/predicate_builder.rb:79:in flat_map'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/relation/predicate_builder.rb:79:in
expand_from_hash'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/relation/predicate_builder.rb:25:in build_from_hash'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/relation/query_methods.rb:1313:in
build_where_clause'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/relation/query_methods.rb:756:in where!'\", \"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/relation/query_methods.rb:751:in
where'", "/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/querying.rb:22:in where'\", \"/var/task/app/controllers/livestream/dash/list.rb:4:in
livestream_dash_list_post'", "/var/task/router.rb:116:in router'\", \"/var/runtime/lib/lambda_handler.rb:26:in
call_handler'", "/var/runtime/lib/runtime.rb:99:in `
Any updates/fixes exptected on this issue?
This is still an issue
I'll take a look at this today.
Not able to make any progress when using yum install mariadb-devel
and getting a static file. Keep running into a undefined symbol: mysql_server_init
error. I recommend you switch to Lambda Containers and do the yum install for mariadb and letting libmysqlclient.so.18 end up in the container's needed location.
Lambda Containers?
What's your recommended way to debug lamby issues? or when you get an issue in prod?I tried running the docker container locally; but I often don't get the same issues I see on my container and once I deploy – and the whole debugging process is pretty slow since I need to deplpoy to test the changes each time.
Here is a good example of how all that works in the latest Lamby Cookiecutter work. rails-lambda/lamby-cookiecutter#21
Basically, there is a 1-1 parity now in dev and prod. Same container is used. Hope that helps?