I have a similar issue on my machine.
One should be able to reproduce the error using the following snippet (system info follows).
The things I have found are:
- This bug doesn't seem to exist using openjdk-8, but it begins in openjdk-11 and effects all higher versions that I have tested.
- The problem seems to be querying SQL from within a
reactive
. Calls outside the reactive are successful.
- I have attempted to instantiate the connection in the global environment, within the server, and within the reactive itself. None of these approaches solve the problem.
- When I examine the connection object, a call to
conn@jc
yields a string like "Java-Object{net.sourceforge.jtds.jdbc.JtdsConnection@13fee20c}"
. Within the reactive, this becomes: "Java-Object{}"
. In particular, the print method for the java object includesrJava::.jstrVal(conn@jc)
which appears to throw the error as well when accessed via rJava::.jcheck()
(again, only within the reactive).
- Upon quitting the app runtime, the same connection becomes functional again.
I wonder if the issue has something to do with some multi-threading magic on the shiny backend. A pointer being misplaced? When I look at my jobj
outside of the reactive, I see <pointer: 0x556992f51450>
, however when the error throws, I see this:
Java Exception <no description because toString() failed>`<reactive:one>`(...)new("jobjRef", jobj = <pointer: 0x556992f51448>, jclass = "java/lang/Throwable")
I'm not sure if those pointers should match or not. They almost do!
Anyway, I'm hopeful someone with more expertise in shiny particularly can help me with this.
library(shiny)
## We are using JTDS, but this problem does not seem to be driver specific, as I
## tested on Microsoft's JDBC driver (version 12) as well.
drvr <- RJDBC::JDBC(
driverClass = "net.sourceforge.jtds.jdbc.Driver",
classPath = Sys.getenv("classPath"))
## Set these environment variables to your username, password, and a connection
## string.
conn <- RJDBC::dbConnect(
drv = drvr,
user = Sys.getenv("user"),
password = Sys.getenv("password"),
Sys.getenv("connectionString"))
## A simple UI.
ui <- bootstrapPage(plotOutput("plot"))
server <- function(input, output){
## This call works.
x <- RJDBC::dbGetQuery(
conn = conn,
statement = "select * from sys.tables")
one <- reactive({
## This call throws an error like the following:
## Warning: Error in .jcheck: Java Exception <no description because
## toString() failed>.jcall(conn@jc, "Z", "getAutoCommit")
## new("jobjRef", jobj = <pointer: 0x564bbbc301d0>, jclass =
## "java/lang/Throwable")
Y <- RJDBC::dbGetQuery(
conn = conn,
statement = "select * from sys.tables")
return(1)
})
## Some dummy output.
output$plot <- renderPlot(plot(one()))
}
## Run the application.
shinyApp(ui = ui, server = server)
And my session info:
R version 4.0.4 (2021-02-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 11 (bullseye)
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C
[3] LC_TIME=C.UTF-8 LC_COLLATE=C.UTF-8
[5] LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C.UTF-8
[9] LC_ADDRESS=C.UTF-8 LC_TELEPHONE=C.UTF-8
[11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_1.7.4
loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 crayon_1.5.2 digest_0.6.30 later_1.3.0
[5] mime_0.12 R6_2.5.1 DBI_1.1.3 jsonlite_1.8.3
[9] lifecycle_1.0.3 xtable_1.8-4 magrittr_2.0.3 RJDBC_0.2-10
[13] cachem_1.0.6 rlang_1.1.0 cli_3.4.1 promises_1.2.0.1
[17] jquerylib_0.1.4 bslib_0.4.2 ellipsis_0.3.2 tools_4.0.4
[21] httpuv_1.6.6 fastmap_1.1.0 compiler_4.0.4 memoise_2.0.1
[25] rJava_1.0-8 htmltools_0.5.4 sass_0.4.2