Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbConnect(check_interrupt = TRUE) broken? #336

Closed
krlmlr opened this issue Sep 19, 2021 · 1 comment · Fixed by #337
Closed

dbConnect(check_interrupt = TRUE) broken? #336

krlmlr opened this issue Sep 19, 2021 · 1 comment · Fixed by #337
Labels
Milestone

Comments

@krlmlr
Copy link
Member

krlmlr commented Sep 19, 2021

The interrupt seems to be caught by select() on the socket, not by Rcpp::checkUserInterrupt() as intended by the code. This leads to an error message Rcpp::exception: select() failed with error code 4 (where 4 means EINTR), and the subsequent cleanup (in an overarching try-catch?) still waits for the query to complete.

Same on macOS and Linux. Not tested on Windows.

session <- callr::r_session$new()

session$run(function() {
  library(RPostgres)
  .GlobalEnv$conn <- dbConnect(Postgres(), check_interrupts = TRUE)
  invisible()
})
#> NULL
session$call(function() {
  tryCatch(
    print(dbGetQuery(.GlobalEnv$conn, "SELECT pg_sleep(2)")),
    error = identity
  )
})

session$poll_process(100)
#> [1] "timeout"
session$read()
#> NULL
session$interrupt()
#> [1] TRUE
# Should take much less than 1.9 seconds
system.time(print(session$poll_process(2000)))
#> [1] "ready"
#>    user  system elapsed 
#>   0.000   0.001   1.904
# Should return a proper error message
session$read()
#> $code
#> [1] 200
#> 
#> $message
#> [1] "done callr-rs-result-f8d028852a34"
#> 
#> $result
#> <Rcpp::exception: select() failed with error code 4>
#> 
#> $stdout
#> [1] ""
#> 
#> $stderr
#> [1] ""
#> 
#> $error
#> NULL
#> 
#> attr(,"class")
#> [1] "callr_session_result"

Created on 2021-09-19 by the reprex package (v2.0.1)

@krlmlr krlmlr added the bug label Sep 19, 2021
@krlmlr krlmlr added this to the 1.4.0 milestone Sep 19, 2021
krlmlr added a commit that referenced this issue Sep 19, 2021
- `dbConnect(check_interrupts = TRUE)` now aborts a running query faster and more reliably when the user signals an interrupt, e.g. by pressing Ctrl+C (#336).
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant