Closed botanize closed 9 months ago
I have the exact same problem on both MacOS and Ubuntu.
If the query yields zero rows then I do not get any problems. But a query yielding rows of data crashes the second time I run it. It does not seem to matter if it is parametrized or non-parametrized.
Downgrading odbc
to 1.3.5 solved the problem on both machines.
Thanks for the issue, yall. I'm not able to reproduce with SQL Server 2022 (same OS, architecture, pkg version and install method)—let me see if I can get a deployment of SQL Server 2016 up and running and test against that.
@michael-dewar, could you provide your devtools::session_info()
as well? What version of SQL Server are you running?
I am seeing a very similar problem since upgrading to ODBC 1.4.1, too. I hope this information is useful:
SQL Server version: 14.00.3451
The error I am getting when running a query the second time is:
*** caught segfault ***
address 0x1e, cause 'memory not mapped'
Traceback:
1: new_result(p = connection@ptr, sql = statement, immediate = immediate)
2: OdbcResult(connection = conn, statement = statement, params = params, immediate = immediate)
3: .local(conn, statement, ...)
4: dbSendQuery(connection, "SELECT * FROM TABLE_NAME")
5: dbSendQuery(connection, "SELECT * FROM TABLE_NAME")
It looks like Microsoft no longer supports SQL server 2016 and 2017 (14.00.3451), and these are both over six years old. Given that this doesn't appear to be a problem with a recent SQL server, I think this means that this unfortunately something that we don't have the time/resources to fix.
Closing this issue, but happy to reopen if we have evidence it affects supported SQL server versions.
I have the problem with both SQL Server 2019 and 2022.
con <- DBI::dbConnect(odbc::odbc(),
driver = "/opt/homebrew/lib/libtdsodbc.so",
server = configs2019$host,
port = configs2019$port,
uid = configs2019$user,
pwd = configs2019$pwd)
"select @@VERSION" |> DBI::dbGetQuery(con, statement = _)
#>
#> 1 Microsoft SQL Server 2019 (RTM-CU23) (KB5030333) - 15.0.4335.1 (X64) \n\tSep 21 2023 17:28:44 \n\tCopyright (C) 2019 Microsoft Corporation\n\tExpress Edition (64-bit) on Windows 10 Pro 10.0 <X64> (Build 22631: ) (Hypervisor)\n
DBI::dbDisconnect(con)
#> Warning in connection_release(conn@ptr): There is a result object still in use.
#> The connection will be automatically released when it is closed
con <- DBI::dbConnect(odbc::odbc(),
driver = "/opt/homebrew/lib/libtdsodbc.so",
server = configs2022$host,
port = configs2022$port,
uid = configs2022$user,
pwd = configs2022$pwd)
"select @@VERSION" |> DBI::dbGetQuery(con, statement = _)
#>
#> 1 Microsoft SQL Server 2022 (RTM-GDR) (KB5029379) - 16.0.1105.1 (X64) \n\tAug 24 2023 02:40:55 \n\tCopyright (C) 2022 Microsoft Corporation\n\tExpress Edition (64-bit) on Windows 10 Enterprise 10.0 <X64> (Build 19045: ) (Hypervisor)\n
DBI::dbDisconnect(con)
#> Warning in connection_release(conn@ptr): There is a result object still in use.
#> The connection will be automatically released when it is closed
Here I'm getting a warning on disconnect. But if I check the version twice in a row I get the crash.
Thanks for the extra info! Just tried out that "select @@VERSION"
on SQL Server 2022 (RTM-CU10) and wasn't able to reproduce. Hm.
I might have solved my problem. Before I was using the FreeTDS ODBC Driver from Homebrew (brew install freetds
). Just now I followed the instructions to install Microsoft's ODBC 18 driver and now every thing works fine.
Incidentally, I needed to faff around to get the MS driver to work. This StackOverflow answer had what I needed.
Hmmm, if this is a problem with the freeTDS odbc driver we should take more of a look (and either fix or possibly just recommend against the freeTDS driver because I'm pretty sure we've seen other problems).
@simonpcouch can you please see if you can reproduce with freeTDS?
Ah, yup. I can reproduce. R 4.3.1, odbc 1.4.1, TDS 7.3, unixODBC, SQL Server 2022, aarch64 MacOS.
To reproduce, work through the SQL Server setup instructions to boot up a SQL Server with Docker. (Replace the double quotes in "MSSQL_SA_PASSWORD=BoopBop123!"
with single quotes--woops.) Then, brew install freetds
.
In odbc.ini
:
[FreeTDSSQLServer]
driver = FreeTDS Driver
Server = 127.0.0.1
port = 1433
Encrypt = no
In odbcinst.ini
:
[FreeTDS Driver]
Description=FreeTDS Driver for SQL server
Driver=/opt/homebrew/Cellar/freetds/1.4.10/lib/libtdsodbc.0.so
Switch out the Driver directory with the one printed out in brew install
if needed.
Then, in freetds.conf
(locate with tsql -C
if needed):
[FreeTDSSQLServer]
host = 127.0.0.1
port = 1433
Encrypt = no
In a fresh R session, the following crashes:
library(odbc)
library(DBI)
con <- dbConnect(
odbc::odbc(),
dsn = "FreeTDSSQLServer",
uid = "SA",
pwd = "BoopBop123!"
)
dbWriteTable(con, "mtcars", mtcars, overwrite = TRUE)
dbGetQuery(con, "SELECT * FROM mtcars")
dbGetQuery(con, "SELECT * FROM mtcars")
I can confirm that I was using the FreeTDS ODBC driver and after switching to the Microsoft ODBC Driver 18, the problem went away.
Is this an issue of the FreeTDS driver then or the compatibility with it?
@tgreger it will take us some time to figure that out, but I suspect that given this code works with all the other drivers we use, it's the FreeTDS at fault. If that's indeed the case, I think the best resolution will be to detect usage of the driver and suggest that the user switches to the MS version.
Issue Description and Expected Result
Multiple
dbGetQuery
calls leads to segfault on macOS. I usedgit bisect
and found the problem was introduced in commit 5b36b47.Database
SQL Server 2016
Reproducible Example
Disconnecting after running a simple query will result in the following warning:
Session Info
```r devtools::session_info() #> ─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── setting value version R version 4.3.2 (2023-10-31) os macOS Sonoma 14.2.1 system aarch64, darwin20 ui X11 language (EN) collate en_US.UTF-8 ctype en_US.UTF-8 tz America/Chicago date 2024-01-02 pandoc 3.1.11 @ /opt/homebrew/bin/pandoc ─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── package * version date (UTC) lib source bit 4.0.5 2022-11-15 [1] CRAN (R 4.3.0) bit64 4.0.5 2020-08-30 [1] CRAN (R 4.3.0) blob 1.2.4 2023-03-17 [1] CRAN (R 4.3.0) cachem 1.0.8 2023-05-01 [1] CRAN (R 4.3.0) cli 3.6.2 2023-12-11 [1] CRAN (R 4.3.1) DBI 1.2.0 2023-12-21 [1] CRAN (R 4.3.2) devtools 2.4.5 2022-10-11 [1] CRAN (R 4.3.0) digest 0.6.33 2023-07-07 [1] CRAN (R 4.3.0) ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.3.0) fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0) fs 1.6.3 2023-07-20 [1] CRAN (R 4.3.0) glue 1.6.2 2022-02-24 [1] CRAN (R 4.3.0) hms 1.1.3 2023-03-21 [1] CRAN (R 4.3.0) htmltools 0.5.7 2023-11-03 [1] CRAN (R 4.3.1) htmlwidgets 1.6.4 2023-12-06 [1] CRAN (R 4.3.1) httpuv 1.6.13 2023-12-06 [1] CRAN (R 4.3.1) later 1.3.2 2023-12-06 [1] CRAN (R 4.3.1) lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.3.1) magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) memoise 2.0.1 2021-11-26 [1] CRAN (R 4.3.0) mime 0.12 2021-09-28 [1] CRAN (R 4.3.0) miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.3.0) nvimcom * 0.9-157 2023-12-01 [1] local odbc * 1.4.1 2023-12-21 [1] CRAN (R 4.3.1) pkgbuild 1.4.3 2023-12-10 [1] CRAN (R 4.3.1) pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0) pkgload 1.3.3 2023-09-22 [1] CRAN (R 4.3.1) profvis 0.3.8 2023-05-02 [1] CRAN (R 4.3.0) promises 1.2.1 2023-08-10 [1] CRAN (R 4.3.0) purrr 1.0.2 2023-08-10 [1] CRAN (R 4.3.0) R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) Rcpp 1.0.11 2023-07-06 [1] CRAN (R 4.3.0) remotes 2.4.2.1 2023-07-18 [1] CRAN (R 4.3.0) rlang 1.1.2 2023-11-04 [1] CRAN (R 4.3.1) sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0) shiny 1.8.0 2023-11-17 [1] CRAN (R 4.3.1) stringi 1.8.3 2023-12-11 [1] CRAN (R 4.3.1) stringr 1.5.1 2023-11-14 [1] CRAN (R 4.3.1) urlchecker 1.0.1 2021-11-30 [1] CRAN (R 4.3.0) usethis 2.2.2 2023-07-06 [1] CRAN (R 4.3.0) vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.3.1) xtable 1.8-4 2019-04-21 [1] CRAN (R 4.3.0) [1] /Users/***/Library/R/arm64/4.3/library [2] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ```