sassoftware / R-swat

The SAS Scripting Wrapper for Analytics Transfer (SWAT) package is the R client to SAS Cloud Analytic Services (CAS). It allows users to execute CAS actions and process the results all from R.
Other
50 stars 22 forks source link

Error when closing and reopening a connection to CAS #15

Closed al-obrien closed 3 years ago

al-obrien commented 5 years ago

While using RSWAT in RStudio I will establish a connection using syntax such as:

# Establish Connection
s <- swat::CAS("CONNECTION/TO/MY/INSTANCE",
               username='MYUSER', password='MYPASS')

I then perform some work. However, if I close this connection, as so cas.close(s), and try to establish the same connection again in the same instance of RStudio, I will often received the following error:

NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
Error in if (result$disposition$severity > 1) { : 
  argument is of length zero

The only was I can re-establish the connection is to close and reopen RStudio.

Any idea as to what this error is trying to tell me? Thanks!

tomweber-sas commented 5 years ago

I think I have an idea. I believe that error is due to the result object not being what is expected in that code. I believe this is happening with the following option set:

options(cas.gen.function.sig=TRUE)

That's the only case I see this happening. If you set that to FALSE, does this error go away? I believe I have a fix for this, but need to validate it some more. And, verify that it's this same case that you are hitting - with this option set.

I saw the error as follows:

>
> caz <- CAS('rdcgrdc', 64173)
NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
NOTE: To generate the functions with signatures (for tab completion), set
      options(cas.gen.function.sig=TRUE).
>
>
> options(cas.gen.function.sig=TRUE)
> cas.close(caz)
[1] 0
> caz <- CAS('rdcgrdc', 64173)
NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
Error in if (result$disposition$severity > 1) { :
  argument is of length zero
>

But with the changes I've made it succeeds (still need to investigate and prove its all working though):

> caz <- CAS('rdcgrdc', 64173)
NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
NOTE: To generate the functions with signatures (for tab completion), set
      options(cas.gen.function.sig=TRUE).
> cas.close(caz)
[1] 0
> options(cas.gen.function.sig=TRUE)
> caz <- CAS('rdcgrdc', 64173)
NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
>

Thanks, Tom

tomweber-sas commented 5 years ago

Looking through the code, I saw 3 other places where this error would happen. I've pushed fixes for all to a branch called issue15 (go figure :) ).

If you want to pull that branch and vet this, that'd be great. To be sure it's addressing your case. Just cuz it works for me ...

Thanks, Tom

al-obrien commented 5 years ago

Hello,

Thank you for the reply. I have used the new set of functions in branch15 and the same error does not appear. However, I do find that after I do the following steps the connection never establishes or takes very long: (1) logged-in, (2) set the options for gen.function.sig (3) closed connection, and (4) Log-in again. I provided the steps taken below.

s <- CAS("CONNECTION/TO/MY/INSTANCE",
               username='MYUSER', password='MYPASS')
NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
NOTE: To generate the functions with signatures (for tab completion), set 
      options(cas.gen.function.sig=TRUE).
> cas.close(s)
[1] 0

s <- CAS("CONNECTION/TO/MY/INSTANCE",
               username='MYUSER', password='MYPASS')
NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
NOTE: To generate the functions with signatures (for tab completion), set 
      options(cas.gen.function.sig=TRUE).
> # Set auto-completion
> options(cas.gen.function.sig=TRUE)
> # Close session
> cas.close(s)
[1] 0

s <- CAS("CONNECTION/TO/MY/INSTANCE",
               username='MYUSER', password='MYPASS')
NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...

To double check, I also ran the current released version and I can confirm the same issue arose.

> s <- swat::CAS("CONNECTION/TO/MY/INSTANCE",
+                username='USR', password='APASSWORD')
NOTE: Connecting to CAS and generating CAS action functions for loaded
      action sets...
Error in if (result$disposition$severity > 1) { : 
  argument is of length zero

Thanks!

tomweber-sas commented 5 years ago

Thanks for confirming. Yes, it does take a long time to generate all of those signatures, and it depends upon how many actions you have loaded. That's why it's disabled by default. That error was happening with the first one, so that failed right away. If you don't have that option set, you shouldn't see this issue, nor should it take very long to connect.

I'll merge this in to master so it'll be available there.

Thanks, Tom

MKTG-MODS commented 5 years ago

His this issue been resolved yet? I am having the exact same "argument is of length zero" issue while connecting to RSWAT in RStudio. I can connect to Python SWAT with no issues. What is the the solution?

Thanks.

=== log of 'argument is of length zero' error under RStudio session ===================== Restarting R session...

library(swat) SWAT 1.4.0 library(httr) library(jsonlite)

Sys.setenv(CAS_CLIENT_SSL_CA_LIST="/opt/sas/viya/config/etc/SASSecurityCertificateFramework/cacerts/trustedcerts.pem") httr::with_verbose(swat::CAS("mycompany.net", 8777, protocol='https', user='myuser', password='mypassword'), data_out=TRUE, data_in=TRUE, info=TRUE, ssl=TRUE)

  • About to connect() to mycompany.net port 8777 (#0)
  • Trying xx.yy.xx.yy...
  • Connected to mycompany.net (xx.yy.xx.yy) port 8777 (#0)
  • Initializing NSS with certpath: sql:/etc/pki/nssdb
  • CAfile: /opt/sas/viya/config/etc/SASSecurityCertificateFramework/cacerts/trustedcerts.pem
  • CApath: none
  • SSL connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
  • Server certificate:
  • subject: CN=mycompany.net
  • start date: Jan 29 18:44:46 2019 GMT
  • expire date: Sep 22 14:59:33 2025 GMT
  • common name: mycompany.net
  • issuer: CN=SAS VIYA Intermediate CA
  • Server auth using Basic with user 'myuser' -> PUT /cas/sessions HTTP/1.1 -> Authorization: Basic aGFsbG06T3NhcGVuMDA1IQ== -> User-Agent: libcurl/7.29.0 r-curl/3.2 httr/1.3.1 -> Host: mycompany.net:8777 -> Accept-Encoding: gzip, deflate -> Accept: application/json, text/xml, application/xml, / -> Content-Length: 0 -> <- HTTP/1.1 200 OK <- Connection: close <- Date: Sat, 01 Jun 2019 14:37:07 GMT <- Public: GET, PUT, HEAD, POST, DELETE, TRACE, OPTIONS, PATCH <- Server: SAS HTTPD 10 <- Origin: https://mycompany.net:8777 <- Cache-Control: no-store <- Pragma: no-cache <- Location: https://mycompany.net:8777/cas/sessions/e5e686e9-10cf-c941-809b-2574ef9d6e95 <- Content-Type: application/vnd.sas.cas.direct.session.id+json <- Content-Length: 54 <- << { "session": "e5e686e9-10cf-c941-809b-2574ef9d6e95" }
kesmit13 commented 5 years ago

@MKTG-MODS A fix for this issue has been committed (7933cfd1b8eca87607b4e5550fadf79241a47b4b), but there hasn't been a new release made that includes the fix yet. If you are only interested in the CAS REST interface, you can install the R SWAT package from the current GitHub repository to get the fix.

kesmit13 commented 5 years ago

@MKTG-MODS I should say that the pushed fix takes care of the "argument is of length zero" error; however, the underlying issue looks to be an issue with the session not being found on the server. Can you connect with another client (maybe Python) and run the session.listsessions action after the first connection closes to see if the session still exists?

I have a feeling you are closing the connection and session is closing as well. Then when you try to reconnect, there is no session to connect to.

MKTG-MODS commented 5 years ago

I hate to be naive, but what is the best way to install a pushed fix from the GitHub site?

I tried the command:

library(githubinstall) > githubinstall("sassoftware/R-swat[vb015]")

but it gives me an error "shared object rswat.so not found", so I feel I am downloading the wrong O/S version of R-SWAT. Should I install inside R or using the R CMD format at the command prompt? I am on 64-bit RHEL Linux O/S.

--=============================================================== $ sudo -i R

R version 3.5.1 (2018-07-02) -- "Feather Spray" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-redhat-linux-gnu (64-bit)

library(githubinstall) githubinstall("sassoftware/R-swat[vb015]") Suggestion:

  • sassoftware/R-swat The SAS Scripting Wrapper for Analytics Transfer (SWAT) package is the R client to SAS Cloud Analytic Services (CAS). It allows users to execute CAS actions and process the results all from R. Do you want to install the package (Y/n)? Y Downloading GitHub repo sassoftware/R-swat@vb015 from URL https://api.github.com/repos/sassoftware/R-swat/zipball/vb015 Installing swat '/usr/lib64/R/bin/R' --no-site-file --no-environ --no-save --no-restore \ --quiet CMD INSTALL \ '/tmp/RtmpN9JRcp/devtools1a86329db4614/sassoftware-R-swat-cc009b5' \ --library='/usr/lib64/R/library' --install-tests
kesmit13 commented 5 years ago

The README on the front page shows how. You won't be able to use the GitHub installer because of the shared library dependency. You won't be able to use CAS binary connections after installing directly from GitHub since only full releases contain the appropriate files. But for REST connections, installing the following way will work:

install.packages('https://github.com/sassoftware/R-swat/archive/master.zip', repos=NULL, type='file')
kesmit13 commented 5 years ago

Alternatively, you could clone the repo, copy the rswat.so from the latest release into the R-swat/src/ directory, then run the install.packages(..., repos=NULL, type='file') using your clone directory as the path.

kesmit13 commented 4 years ago

A new release has been created with all of the fixes up until now. Is there still an issue that needs to be looked at here, or can this be closed?