Error in .jcheck: Java Exception <no description because toString() failed

I have a shiny app that works fine in my laptop. However, when I deploy it to shinyapp.io, I get the error message in the title above. It uses RJDBC to connect to a database to get data. I am confused why it works locally but not in shinyapps.io. Below is the session info for my local R installation. Further, rJava::.jinit() returns 0.

sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

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

other attached packages:
[1] rsconnect_0.8.29 DT_0.26 plotly_4.10.1
[4] ggplot2_3.4.0 gridExtra_2.3 RJDBC_0.2-10
[7] rJava_1.0-6 DBI_1.1.3 openxlsx_4.2.5.1
[10] purrr_1.0.0 lubridate_1.9.0 timechange_0.1.1
[13] tidyr_1.2.1 dplyr_1.0.10 shiny_1.7.4

loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 assertthat_0.2.1 digest_0.6.31
[4] packrat_0.9.0 utf8_1.2.2 mime_0.12
[7] R6_2.5.1 httr_1.4.4 pillar_1.8.1
[10] rlang_1.0.6 lazyeval_0.2.2 curl_4.3.3
[13] fontawesome_0.4.0 rstudioapi_0.14 data.table_1.14.6
[16] jquerylib_0.1.4 htmlwidgets_1.6.0 munsell_0.5.0
[19] compiler_4.2.2 httpuv_1.6.7 pkgconfig_2.0.3
[22] askpass_1.1 htmltools_0.5.4 openssl_2.0.5
[25] tidyselect_1.2.0 tibble_3.1.8 fansi_1.0.3
[28] viridisLite_0.4.1 withr_2.5.0 later_1.3.0
[31] grid_4.2.2 jsonlite_1.8.4 xtable_1.8-4
[34] gtable_0.3.1 lifecycle_1.0.3 magrittr_2.0.3
[37] scales_1.2.1 zip_2.2.2 cli_3.5.0
[40] stringi_1.7.8 cachem_1.0.6 promises_1.2.0.1
[43] bslib_0.4.2 ellipsis_0.3.2 generics_0.1.3
[46] vctrs_0.5.1 tools_4.2.2 glue_1.6.2
[49] crosstalk_1.2.0 fastmap_1.1.0 yaml_2.3.6
[52] colorspace_2.0-3 memoise_2.0.1 sass_0.4.4

Could you check what your app's logs say?

@andresrcs , these are the logs. Thank you!

2023-03-14T18:53:05.239337+00:00 shinyapps[6644300]: Loading required package: DBI
2023-03-14T18:53:05.340986+00:00 shinyapps[6644300]: Loading required package: rJava
2023-03-14T18:53:05.810760+00:00 shinyapps[6644300]: Attaching package: ‘gridExtra’
2023-03-14T18:53:05.811033+00:00 shinyapps[6644300]: The following object is masked from ‘package:dplyr’:
2023-03-14T18:53:05.811066+00:00 shinyapps[6644300]:     combine
2023-03-14T18:53:05.814230+00:00 shinyapps[6644300]: Loading required package: ggplot2
2023-03-14T18:53:06.041922+00:00 shinyapps[6644300]: Attaching package: ‘plotly’
2023-03-14T18:53:06.042131+00:00 shinyapps[6644300]: The following object is masked from ‘package:ggplot2’:
2023-03-14T18:53:06.042155+00:00 shinyapps[6644300]:     last_plot
2023-03-14T18:53:06.042339+00:00 shinyapps[6644300]: The following object is masked from ‘package:stats’:
2023-03-14T18:53:06.042357+00:00 shinyapps[6644300]:     filter
2023-03-14T18:53:06.042537+00:00 shinyapps[6644300]: The following object is masked from ‘package:graphics’:
2023-03-14T18:53:06.042546+00:00 shinyapps[6644300]:     layout
2023-03-14T18:53:06.053715+00:00 shinyapps[6644300]: Attaching package: ‘DT’
2023-03-14T18:53:06.053941+00:00 shinyapps[6644300]: The following objects are masked from ‘package:shiny’:
2023-03-14T18:53:06.053953+00:00 shinyapps[6644300]:     dataTableOutput, renderDataTable
2023-03-14T18:53:06.062235+00:00 shinyapps[6644300]: Attaching package: ‘rsconnect’
2023-03-14T18:53:06.062466+00:00 shinyapps[6644300]: The following object is masked from ‘package:shiny’:
2023-03-14T18:53:06.062479+00:00 shinyapps[6644300]:     serverInfo
2023-03-14T18:53:07.038850+00:00 shinyapps[6644300]: Listening on http://127.0.0.1:40427
2023-03-14T18:53:30.638781+00:00 shinyapps[6644300]: Warning: Error in .jcheck: Java Exception <no description because toString() failed>.jcall(conn@jc, "Ljava/sql/Statement;", "createStatement")new("jobjRef", jobj = <pointer: 0x55e2cfc86678>, jclass = "java/lang/Throwable")
2023-03-14T18:53:30.662572+00:00 shinyapps[6644300]:   175: stop
2023-03-14T18:53:30.662616+00:00 shinyapps[6644300]:   174: .jcheck
2023-03-14T18:53:30.662623+00:00 shinyapps[6644300]:   173: .jcall
2023-03-14T18:53:30.662629+00:00 shinyapps[6644300]:   172: .local
2023-03-14T18:53:30.662635+00:00 shinyapps[6644300]:   171: dbSendQuery
2023-03-14T18:53:30.662663+00:00 shinyapps[6644300]:   169: .local
2023-03-14T18:53:30.662669+00:00 shinyapps[6644300]:   168: dbGetQuery
2023-03-14T18:53:30.662674+00:00 shinyapps[6644300]:   163: eventReactiveValueFunc [/srv/connect/apps/test2/app.R#135]
2023-03-14T18:53:30.662685+00:00 shinyapps[6644300]:   119: sales_final_df
2023-03-14T18:53:30.662690+00:00 shinyapps[6644300]:   118: exprFunc
2023-03-14T18:53:30.662695+00:00 shinyapps[6644300]:   117: widgetFunc
2023-03-14T18:53:30.662699+00:00 shinyapps[6644300]:   116: ::
2023-03-14T18:53:30.662711+00:00 shinyapps[6644300]: htmlwidgets
2023-03-14T18:53:30.662716+00:00 shinyapps[6644300]: shinyRenderWidget
2023-03-14T18:53:30.662721+00:00 shinyapps[6644300]:   115: func
2023-03-14T18:53:30.662725+00:00 shinyapps[6644300]:   102: renderFunc
2023-03-14T18:53:30.662730+00:00 shinyapps[6644300]:   101: renderFunc
2023-03-14T18:53:30.662737+00:00 shinyapps[6644300]:    97: renderFunc
2023-03-14T18:53:30.662742+00:00 shinyapps[6644300]:    96: output$sales_final
2023-03-14T18:53:30.662751+00:00 shinyapps[6644300]:    15: <Anonymous>
2023-03-14T18:53:30.662758+00:00 shinyapps[6644300]:    13: fn
2023-03-14T18:53:30.662762+00:00 shinyapps[6644300]:     8: retry
2023-03-14T18:53:30.662768+00:00 shinyapps[6644300]:     7: connect$retryingStartServer
2023-03-14T18:53:30.662786+00:00 shinyapps[6644300]:     6: eval
2023-03-14T18:53:30.662811+00:00 shinyapps[6644300]:     5: eval
2023-03-14T18:53:30.662816+00:00 shinyapps[6644300]:     4: eval
2023-03-14T18:53:30.662828+00:00 shinyapps[6644300]:     3: eval
2023-03-14T18:53:30.662831+00:00 shinyapps[6644300]:     2: eval.parent
2023-03-14T18:53:30.662844+00:00 shinyapps[6644300]:     1: local

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