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

R connection using library RPostgres fails with error "received invalid response to GSSAPI negotiation: R" #227

Closed
mskyttner opened this issue Dec 2, 2021 · 5 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@mskyttner
Copy link

mskyttner commented Dec 2, 2021

ArcadeDB Version: v21.12.1-SNAPSHOT

JDK Version: arcadedata/arcadedb:latest (docker image)

OS: arcadedata/arcadedb:latest (docker image)

Expected behavior

Attempt to connect using R and RPostgres expected to work, since RJDBC is able to read data from a table in arcadedb.

Actual behavior

Error "received invalid response to GSSAPI negotiation: R"

Steps to reproduce

arcadedb_cmd <- paste(
  "docker run -d -p '2480:2480' -p '2424:2424' -p '5432:5432'",
  "--env arcadedb.server.rootPassword=playwithdata",
  "--env 'arcadedb.server.defaultDatabases=Imported[root]{import:https://github.com/ArcadeData/arcadedb-datasets/raw/main/orientdb/OpenBeer.gz}'", 
  "--env arcadedb.server.plugins='Postgres:com.arcadedb.postgres.PostgresProtocolPlugin'", 
  "arcadedata/arcadedb:latest"
)

cmd <- gsub("\n", "", arcadedb_cmd)

# launch the background service with arcadedb using docker
system(arcadedb_cmd)

# check that it is online using the API
arcadedb_is_up <- function() {
  
  res <- httr::content(
    httr::GET("http://localhost:2480/api/v1/databases", 
    httr::authenticate("root", "playwithdata"))
  )
  
  res$result[[1]] == "Imported"
}

stopifnot(arcadedb_is_up())

# This "works", using RJDBC and the pg jdbc driver

download.file(
  "https://jdbc.postgresql.org/download/postgresql-42.3.1.jar",
  "~/repos/arcadedb/postgresql-42.3.1.jar"
)

library(RJDBC)

drv <- JDBC(
  driverClass = "org.postgresql.Driver", 
  classPath = "~/repos/arcadedb/postgresql-42.3.1.jar", 
  identifier.quote = "`"
)

conn <- dbConnect(drv, 
  paste0("jdbc:postgresql://localhost/Imported",
    "?user=root&password=playwithdata&ssl=false&gssencmode=disable"))

tibble::as_tibble(dbGetQuery(conn, "select * from Brewery limit 10;"))

dbDisconnect(conn)

# Now, attempt to use RPostgres which uses libpg and no Java

library(RPostgres)
library(DBI)

#Sys.setenv(PGGSSENCMODE="disable")
Sys.unsetenv("PGGSSENCMODE")

con <- dbConnect(
  RPostgres::Postgres(),
#  gssencmode = 'disable',
  dbname = 'Imported',
  host = 'localhost',
  port = 5432, 
  user = 'root',
  password = 'playwithdata'
)

# Error: connection to server at "localhost" (127.0.0.1), port 5432 failed: received invalid response to GSSAPI negotiation: R
# Can this be worked around by disabling GSSENCMODE?
# see https://stackoverflow.com/questions/67396081/how-to-configure-a-odbc-connection-to-teiid-on-rhel8-gssapi-negotiation-fails
# and https://blog.hagander.net/connecting-to-azure-postgresql-with-libpq-12-in-a-kerberos-environment-245/
@lvca lvca self-assigned this Dec 2, 2021
@lvca
Copy link
Contributor

lvca commented Dec 2, 2021

Is it possible is the same issue as for https://githubmemory.com/repo/r-dbi/RPostgres/issues/310?

Please disable SSL with the connection: it's not supported yet but it's low priority assuming you're connecting client and server in a local (trusted) network.

@lvca lvca added the bug Something isn't working label Dec 2, 2021
@lvca lvca added this to the 21.12.1 milestone Dec 2, 2021
@mskyttner
Copy link
Author

I logged an issue with the RPostgres package and made an attempt to disable SSL but the connection still "hangs".

r-dbi/RPostgres#363

For me, the OpenBeer database running in under docker uses 2.2 GB of RAM (from docker stats). Are there any docs regarding memory limits for arcadedb, say if I wanted to run it with only 1 or a 0.5 GB of RAM, are there any settings/parameters that could be tweaked to allow this?

@lvca
Copy link
Contributor

lvca commented Dec 3, 2021

You're right, our docs lack this information. I'm gonna improve it today. For now I report here my comment on R-DB issue:

You can set in ArcadeDB's docker -Darcadedb.profile=low-ram to run ArcadeDB with <32M of RAM and see how it goes. In general, the RAM allocated for the JVM should be <=80% of the container RAM.

The default Dockerfile sets 2GB of RAM for ArcadeDB (-Xms2G -Xmx2G), so you should allocate around 2.3G to the Docker container.

To run ArcadeDB with 1G docker container, you could start ArcadeDB by using 800M for RAM:

docker .. -e ARCADEDB_OPTS_MEMORY="-Xms800M -Xmx800M" ...

@lvca
Copy link
Contributor

lvca commented Dec 3, 2021

Added this paragraph hoping helps a little more, any suggestions to improve it are welcome: https://docs.arcadedb.com/#DockerTuning

@lvca lvca removed this from the 21.12.1 milestone Dec 31, 2021
lvca added a commit that referenced this issue Jan 4, 2022
@lvca
Copy link
Contributor

lvca commented Jan 4, 2022

@mskyttner fixed in the latest "main" branch and 22.1.1-SNAPSHOT (now the latest) on Docker Hub. Please let me know if works for you. I tested with the following script and works.

.libPaths( c( "/usr/local/lib/R/lib" , .libPaths() ) )

r = getOption("repos")
r["CRAN"] = "http://cran.us.r-project.org"
options(repos = r)

##install.packages(c("RPostgres"), lib="/usr/local/lib/R/lib")
##install.packages(c("DBI"), lib="/usr/local/lib/R/lib")

library(DBI)

#Sys.setenv(PGGSSENCMODE="disable")
#Sys.unsetenv("PGGSSENCMODE")
#Sys.unsetenv("PGSSLMODE")
#Sys.setenv(PGSSLMODE="disable")

con <- dbConnect(
  RPostgres::Postgres(),
  gssencmode = 'disable',
  sslmode = "disable",
  dbname = 'Beer',
  host = 'localhost',
  port = 5432,
  user = 'root',
  password = 'playwithdata'
)

print("EXECUTING QUERY")

res <- dbSendQuery(con, "select * from Brewery limit 10")

print("FETCHING RESULTS")

dbFetch(res)

print("CLEARING RESULTS")
dbClearResult(res)
dbDisconnect(con)

Now I have to find a way to include the R test suite in our CI pipeline... @arcade-player any help?

@lvca lvca closed this as completed Jan 4, 2022
@lvca lvca added this to the 22.1.1 milestone Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants