r-dbi / RMariaDB

An R interface to MariaDB
https://rmariadb.r-dbi.org
Other
130 stars 40 forks source link

Failed to connect to database: Error: SSL connection error: SSL_CTX_set_tmp_dh failed #128

Closed AlistairLR112 closed 4 years ago

AlistairLR112 commented 5 years ago

Hello all, I am currently receiving the following error when attempting to connect to an AWS RDS instance inside of a Docker container hosted on Kubernetes.

ERROR [2019-02-28 16:07:58] Error in .local(drv, ...): Failed to connect to database: Error: SSL connection error: SSL_CTX_set_tmp_dh failed

We are not using any PKIs so I am unsure why this is happening.

The Dockerfile contains the following lines (bottom part omitted)

FROM continuumio/miniconda
WORKDIR /app/
RUN apt-get update && apt-get install libcurl4-openssl-dev -y && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y libmariadb-client-lgpl-dev
RUN conda update -n base -c defaults conda

The code being ran is the following:

library(dplyr)
library(plotly)
library(DBI)
library(RMariaDB)
library(lubridate)
library(tibble)
library(jsonlite)
library(futile.logger)
library(hms)
library(forcats)

open_conn = function(){
  conn = dbConnect(drv = MariaDB(),
                   username = Sys.getenv("MYSQL_USER"),
                   password = Sys.getenv("MYSQL_PASSWORD"),
                   host     = Sys.getenv("MYSQL_HOST"),
                   port     = as.integer(Sys.getenv("MYSQL_PORT")),
                   dbname   = Sys.getenv("MYSQL_DATABASE"))
  return(conn)
}

conn = tryCatch(
    open_conn(),
    error = function(e) {
      flog.error(e)
      flog.error("Could not open DB connection")
      stop(e)
    }

My sessionInfo() is as follows

R version 3.5.1 (2018-07-02)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS/LAPACK: /opt/conda/envs/app-environment/lib/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
 [1] forcats_0.3.0       hms_0.4.2           futile.logger_1.4.3
 [4] tibble_2.0.1        lubridate_1.7.4     RMariaDB_1.0.6
 [7] DBI_1.0.0           dplyr_0.7.8         jsonlite_1.6
[10] plotly_4.8.0        ggplot2_3.1.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0           formatR_1.5          pillar_1.3.1
 [4] compiler_3.5.1       later_0.8.0          plyr_1.8.4
 [7] bindr_0.1.1          futile.options_1.0.1 tools_3.5.1
[10] bit_1.1-12           digest_0.6.18        viridisLite_0.3.0
[13] gtable_0.2.0         pkgconfig_2.0.2      rlang_0.3.1
[16] bindrcpp_0.2.2       stringr_1.4.0        withr_2.1.2
[19] httr_1.4.0           htmlwidgets_1.3      bit64_0.9-7
[22] grid_3.5.1           tidyselect_0.2.5     glue_1.3.0
[25] data.table_1.12.0    R6_2.4.0             lambda.r_1.2.3
[28] plumber_0.4.4        purrr_0.2.5          tidyr_0.8.2
[31] magrittr_1.5         scales_1.0.0         promises_1.0.1
[34] htmltools_0.3.6      assertthat_0.2.0     colorspace_1.4-0
[37] httpuv_1.4.5.1       stringi_1.2.4        lazyeval_0.2.1
[40] munsell_0.5.0        crayon_1.3.4
krlmlr commented 5 years ago

Thanks. Is there any chance I could terraform or otherwise replicate this?

Googling found this, I have no idea if it's applicable: https://stackoverflow.com/a/53387095/946850.

krlmlr commented 4 years ago

Closing, can't reproduce.

tingjhenjiang commented 4 years ago

I got the same issue. My env is: Host is Windows 10; MySQL is running on a Docker container, where Docker is installed in Windows. Rstudio(R env) is running under Windows Subsystem using Rstudio-server.

But, if I run my Rstudio(R env) under Windows using rstudio desktop, there is no problem connecting to MySQL docker container.

krlmlr commented 4 years ago

Thanks. Can you please show the output of:

DBI::dbGetInfo(RMariaDB::MariaDB())
tingjhenjiang commented 4 years ago

Thanks. Can you please show the output of:

DBI::dbGetInfo(RMariaDB::MariaDB())

In Windows Subsystem R env(rstudio server) (where MySQL server hosts in a container of Docker for Windows). package installation by running conda install -c conda-forge r-dbi and conda install -c conda-forge r-rmariadb, which later would encounter "SSL_CTX_set_tmp_dh failed":

> DBI::dbGetInfo(RMariaDB::MariaDB())
Error in (function (classes, fdef, mtable)  : 
unable to find an inherited method for function ‘dbGetInfo’ for signature ‘"MariaDBDriver"’

in the same R env(rstudio server):

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS/LAPACK: /home/j/miniconda3/envs/tf2/lib/libopenblasp-r0.3.7.so

locale:
 [1] LC_CTYPE=zh_TW.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=zh_TW.UTF-8        LC_COLLATE=zh_TW.UTF-8    
 [5] LC_MONETARY=zh_TW.UTF-8    LC_MESSAGES=zh_TW.UTF-8   
 [7] LC_PAPER=zh_TW.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=zh_TW.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached):
 [1] bit_1.1-14      compiler_3.6.1  backports_1.1.5 hms_0.5.2      
 [5] DBI_1.0.0       tools_3.6.1     pillar_1.4.2    RMariaDB_1.0.7 
 [9] rstudioapi_0.10 tibble_2.1.3    crayon_1.3.4    Rcpp_1.0.3     
[13] bit64_0.9-7     vctrs_0.2.0     zeallot_0.1.0   pkgconfig_2.0.3
[17] rlang_0.4.2    

In Windows 10 R env(rstudio-desktop) (where MySQL server hosts in a container of Docker for Windows, and connection by RMariaDB is fine) :


> DBI::dbGetInfo(RMariaDB::MariaDB())
$driver.version
[1] ‘1.0.8’
$client.version
[1] ‘5.5.1’

> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Traditional)_Taiwan.950 
[2] LC_CTYPE=Chinese (Traditional)_Taiwan.950   
[3] LC_MONETARY=Chinese (Traditional)_Taiwan.950
[4] LC_NUMERIC=C                                
[5] LC_TIME=Chinese (Traditional)_Taiwan.950    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3      zeallot_0.1.0   crayon_1.3.4    DBI_1.1.0       backports_1.1.5
 [6] pillar_1.4.3    rlang_0.4.2     rstudioapi_0.10 vctrs_0.2.1     tools_3.6.2    
[11] bit64_0.9-7     bit_1.1-14      hms_0.5.2       yaml_2.2.0      RMariaDB_1.0.8 
[16] compiler_3.6.2  pkgconfig_2.0.3 tibble_2.1.3   

It is worth noting that, in a R env in Windows Subsystem of the other remote computer, which does not host MySQL server but make connection to other MySQL servers only (also the same target MySQL server), the connection with using DBI and RMariadb would be fine. The R env of that remote computer is:

> DBI::dbGetInfo(RMariaDB::MariaDB())
error: invalid version specification ‘10.1.43-MariaDB’

> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=zh_TW.UTF-8       LC_NUMERIC=C               LC_TIME=zh_TW.UTF-8       
 [4] LC_COLLATE=zh_TW.UTF-8     LC_MONETARY=zh_TW.UTF-8    LC_MESSAGES=zh_TW.UTF-8   
 [7] LC_PAPER=zh_TW.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=zh_TW.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3          zeallot_0.1.0       crayon_1.3.4        DBI_1.1.0.9000     
 [5] backports_1.1.5     pillar_1.4.0        rlang_0.4.2         rstudioapi_0.10    
 [9] vctrs_0.2.1         tools_3.6.2         bit64_0.9-7         bit_1.1-14         
[13] hms_0.5.2           yaml_2.2.0          RMariaDB_1.0.8.9000 compiler_3.6.2     
[17] pkgconfig_2.0.3     tibble_2.1.1
tingjhenjiang commented 4 years ago

After I reset my conda env, the RMariadb is working fine, but I don't know why. Here's the background information of my Renv (running on Windows Subsystem for Linux 2 (WSL 2), which is not an env provides MySQL server service, instead MySQL service is still running on a docker for Windows container:

> DBI::dbGetInfo(RMariaDB::MariaDB())
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘dbGetInfo’ for signature ‘"MariaDBDriver"’
> 
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS/LAPACK: /home/j/miniconda3/envs/tf2/lib/libopenblasp-r0.3.7.so

locale:
 [1] LC_CTYPE=zh_TW.UTF-8       LC_NUMERIC=C               LC_TIME=zh_TW.UTF-8       
 [4] LC_COLLATE=zh_TW.UTF-8     LC_MONETARY=zh_TW.UTF-8    LC_MESSAGES=zh_TW.UTF-8   
 [7] LC_PAPER=zh_TW.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=zh_TW.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] bit_1.1-14      compiler_3.6.2  hms_0.4.2       DBI_1.0.0       tools_3.6.2    
 [6] RMariaDB_1.0.6  Rcpp_1.0.1      bit64_0.9-7     pkgconfig_2.0.2 rlang_0.4.2
krlmlr commented 4 years ago

Thanks for the update.

github-actions[bot] commented 3 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.