yonicd / carbonate

carbon.js for R

Home Page:https://yonicd.github.io/carbonate/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

port = 4567 is already in use

moodymudskipper opened this issue · comments

Describe the bug

I get :

port = 4567 is already in use

when running the simplest example

To Reproduce

library(carbonate)
x <- carbon$new('x <- 1')
x$carbonate()
#> starting chrome session...
#> checking chromedriver versions:
#> BEGIN: PREDOWNLOAD
#> BEGIN: DOWNLOAD
#> BEGIN: POSTDOWNLOAD
#> Error in wdman::selenium(port = port, verbose = verbose, version = version, : Selenium server signals port = 4567 is already in use.

contents of your _mrgconfig.yml file

Not sure where to find this

Expected behavior

open a browser to the carbon.js uri, create an image and download the file

Environment (please complete the following information):

Session Info
- Session info ----------------------------------------------------------------------------------------------
setting  value                       
version  R version 3.6.1 (2019-07-05)
os       Windows 10 x64              
system   x86_64, mingw32             
ui       RStudio                     
language (EN)                        
collate  English_United Kingdom.1252 
ctype    English_United Kingdom.1252 
tz       Europe/Paris                
date     2020-02-14                  

- Packages --------------------------------------------------------------------------------------------------
package     * version    date       lib source                        
askpass       1.1        2019-01-13 [1] CRAN (R 3.6.0)                
assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                
backports     1.1.5      2019-10-02 [1] CRAN (R 3.6.1)                
binman        0.1.1      2018-07-18 [1] CRAN (R 3.6.0)                
bitops        1.0-6      2013-08-17 [1] CRAN (R 3.6.0)                
callr         3.4.0      2019-12-09 [1] CRAN (R 3.6.1)                
carbonate   * 0.1.2      2019-02-13 [1] CRAN (R 3.6.1)                
caTools       1.17.1.3   2019-11-30 [1] CRAN (R 3.6.1)                
cli           2.0.1      2020-01-08 [1] CRAN (R 3.6.2)                
clipr         0.7.0      2019-07-23 [1] CRAN (R 3.6.1)                
crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)                
curl          4.3        2019-12-02 [1] CRAN (R 3.6.1)                
desc          1.2.0      2018-05-01 [1] CRAN (R 3.6.0)                
devtools      2.2.1      2019-09-24 [1] CRAN (R 3.6.1)                
digest        0.6.23     2019-11-23 [1] CRAN (R 3.6.1)                
ellipsis      0.3.0      2019-09-20 [1] CRAN (R 3.6.1)                
fansi         0.4.1      2020-01-08 [1] CRAN (R 3.6.1)                
fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.1)                
glue          1.3.1      2019-03-12 [1] CRAN (R 3.6.0)                
httr          1.4.1      2019-08-05 [1] CRAN (R 3.6.1)                
jsonlite      1.6.1      2020-02-02 [1] CRAN (R 3.6.2)                
magick        2.2        2019-08-26 [1] CRAN (R 3.6.1)                
magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.0)                
memoise       1.1.0.9000 2019-06-12 [1] Github (r-lib/memoise@1650ad7)
openssl       1.4.1      2019-07-18 [1] CRAN (R 3.6.1)                
packrat       0.5.0      2018-11-14 [1] CRAN (R 3.6.0)                
pkgbuild      1.0.6      2019-10-09 [1] CRAN (R 3.6.1)                
pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.0)                
prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.6.0)                
processx      3.4.1      2019-07-18 [1] CRAN (R 3.6.1)                
ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.0)                
R6            2.4.1      2019-11-12 [1] CRAN (R 3.6.1)                
rappdirs      0.3.1      2016-03-28 [1] CRAN (R 3.6.0)                
Rcpp          1.0.3      2019-11-08 [1] CRAN (R 3.6.1)                
remotes       2.1.0      2019-06-24 [1] CRAN (R 3.6.1)                
rlang         0.4.4      2020-01-28 [1] CRAN (R 3.6.2)                
rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.0)                
RSelenium     1.7.5      2019-01-03 [1] CRAN (R 3.6.0)                
rstudioapi    0.11       2020-02-07 [1] CRAN (R 3.6.1)                
rtweet        0.6.9      2019-05-19 [1] CRAN (R 3.6.1)                
semver        0.2.0      2017-01-06 [1] CRAN (R 3.6.0)                
sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                
subprocess    0.8.3      2018-08-13 [1] CRAN (R 3.6.0)                
testthat      2.3.1      2019-12-01 [1] CRAN (R 3.6.1)                
usethis       1.5.1      2019-07-04 [1] CRAN (R 3.6.1)                
wdman         0.2.4      2018-07-21 [1] CRAN (R 3.6.0)                
withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.0)                
XML           3.98-1.20  2019-06-06 [1] CRAN (R 3.6.0)                
xml2          1.2.2      2019-08-09 [1] CRAN (R 3.6.1)                
yaml          2.2.1      2020-02-01 [1] CRAN (R 3.6.2)                

[1] C:/Program Files/R/R-3.6.1/library

Thanks for opening this issue!

_mrgconfig.yml file is a bad copy paste from another template. that should be carbon.yml if you have one.

This is the culprit. https://github.com/yonicd/carbonate/blob/master/R/selenium_functions.R#L44

@ColinFay is there a way to find an open port?

There is an internal function in shiny and markdown that does that.

There are also a bunch of node js packages that do that so might be worth checking how they do it too.

this commit bb0fd55 should solve the issue.

ht to @dpastoor for pointing to how {fiery} finds a port.

in practice the user wont feel the change, but there is now a random port being selected on carb <- carbon$new()

a new one or a specific one can be reset using carb$set_port() or carb$set_port(1234)

> carb <- carbon$new()
Set via '~/carbon.yml'
palette:
- 171.0
- 175.0
- 195.0
- 0.7
template: panda-syntax
font_family: Fira Code
padding_vertical: 11
padding_horizontal: 14
language: r
> carb$get_port()
[1] 51627
> carb$set_port()
> carb$get_port()
[1] 59012
> carb$set_port(1234)
> carb$get_port()
[1] 1234
> class(carb$get_port())
[1] "integer"

You can also try with httpuv::randomPort()

I mean, if the port is not available, switch to a random port (if 4567 is important, if it's not, default to randomPort() )

Is there a way to release unused ports along same lines of gc()? Or does that happen anyways with RSelenium/wdman?

Unfortunately it still doesn't work for me, see below :

library(carbonate)
x <- carbon$new('x <- 1')
x$carbonate()
#> starting chrome session...
#> checking chromedriver versions:
#> BEGIN: PREDOWNLOAD
#> BEGIN: DOWNLOAD
#> BEGIN: POSTDOWNLOAD
#> Error in wdman::selenium(port = port, verbose = verbose, version = version, : Selenium server signals port = 25855 is already in use.

x$carbonate()
#> starting chrome session...
#> Error in wdman::selenium(port = port, verbose = verbose, version = version, : Selenium server signals port = 25855 is already in use.

x <- carbon$new('x <- 1')
x$carbonate()
#> starting chrome session...
#> checking chromedriver versions:
#> BEGIN: PREDOWNLOAD
#> BEGIN: DOWNLOAD
#> BEGIN: POSTDOWNLOAD
#> Error in wdman::selenium(port = port, verbose = verbose, version = version, : Selenium server signals port = 30318 is already in use.

Created on 2020-02-24 by the reprex package (v0.3.0)

thanks for the feedback. i'll try again :)

interesting though that you are landing on unavailable ports that are chosen at random

i thought it may be the reperex envir ... but it's not

library(carbonate)
x <- carbon$new('x <- 1')
#> Set via '~/carbon.yml'
#> palette:
#> - 171.0
#> - 175.0
#> - 195.0
#> - 0.7
#> template: panda-syntax
#> font_family: Fira Code
#> padding_vertical: 11
#> padding_horizontal: 14
#> language: r
x$carbonate()
#> starting chrome session...
#> checking chromedriver versions:
#> BEGIN: PREDOWNLOAD
#> BEGIN: DOWNLOAD
#> BEGIN: POSTDOWNLOAD

Created on 2020-02-24 by the reprex package (v0.3.0)

i see that

wdman is 0.2.4 for you, i am using 0.2.5.
RSelenium is 1.7.5 for you, i am using 1.7.7.

sessioninfo
 package    * version   date       lib source        
 askpass      1.1       2019-01-13 [1] CRAN (R 3.6.0)
 assertthat   0.2.1     2019-03-21 [1] CRAN (R 3.6.0)
 binman       0.1.1     2018-07-18 [1] CRAN (R 3.6.0)
 bitops       1.0-6     2013-08-17 [1] CRAN (R 3.6.0)
 caTools      1.17.1.2  2019-03-06 [1] CRAN (R 3.6.0)
 curl         4.3       2019-12-02 [1] CRAN (R 3.6.0)
 httr         1.4.1     2019-08-05 [1] CRAN (R 3.6.0)
 jsonlite     1.6.1     2020-02-02 [1] CRAN (R 3.6.0)
 mime         0.9       2020-02-04 [1] CRAN (R 3.6.0)
 openssl      1.4.1     2019-07-18 [1] CRAN (R 3.6.0)
 processx     3.4.2     2020-02-09 [1] CRAN (R 3.6.1)
 ps           1.3.2     2020-02-13 [1] CRAN (R 3.6.1)
 R6           2.4.1     2019-11-12 [1] CRAN (R 3.6.0)
 rappdirs     0.3.1     2016-03-28 [1] CRAN (R 3.6.0)
 Rcpp         1.0.3     2019-11-08 [1] CRAN (R 3.6.1)
 RSelenium    1.7.7     2020-02-03 [1] CRAN (R 3.6.1)
 semver       0.2.0     2017-01-06 [1] CRAN (R 3.6.0)
 sys          3.3       2019-08-21 [1] CRAN (R 3.6.1)
 wdman        0.2.5     2020-01-31 [1] CRAN (R 3.6.0)
 XML          3.98-1.20 2019-06-06 [1] CRAN (R 3.6.0)
 xml2         1.2.2     2019-08-09 [1] CRAN (R 3.6.0)
 yaml         2.2.1     2020-02-01 [1] CRAN (R 3.6.0)

[1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library

can you update and try again?

After going through hell and back a handful of times I have R up to date with all latest package versions.

An unfortunate difference is that I can't reprex anymore the example above from Rstudio, The call to reprex seems to complete but doesn't display anything, then any next instruction freezes forever and I have to kill RStudio.

Apart from that I get same error message, I first had a different one though, which told me I had to update chrome to version 81. 81 is the beta version but updating to last available version was enough.

From a clean Rgui session I get :

> library(carbonate)
> sessioninfo::session_info()
- Session info ---------------------------------------------------------------
 setting  value                       
 version  R version 3.6.2 (2019-12-12)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       Rgui                        
 language (EN)                        
 collate  English_United Kingdom.1252 
 ctype    English_United Kingdom.1252 
 tz       Europe/Paris                
 date     2020-02-24                  

- Packages -------------------------------------------------------------------
 package     * version  date       lib source                           
 askpass       1.1      2019-01-13 [1] CRAN (R 3.6.0)                   
 assertthat    0.2.1    2019-03-21 [1] CRAN (R 3.6.0)                   
 binman        0.1.1    2018-07-18 [1] CRAN (R 3.6.0)                   
 bitops        1.0-6    2013-08-17 [1] CRAN (R 3.6.0)                   
 carbonate   * 0.1.4    2020-02-24 [1] Github (yonicd/carbonate@7af4f48)
 caTools       1.18.0   2020-01-17 [1] CRAN (R 3.6.2)                   
 cli           2.0.1    2020-01-08 [1] CRAN (R 3.6.2)                   
 clipr         0.7.0    2019-07-23 [1] CRAN (R 3.6.1)                   
 crayon        1.3.4    2017-09-16 [1] CRAN (R 3.6.0)                   
 curl          4.3      2019-12-02 [1] CRAN (R 3.6.1)                   
 fansi         0.4.1    2020-01-08 [1] CRAN (R 3.6.1)                   
 glue          1.3.1    2019-03-12 [1] CRAN (R 3.6.0)                   
 httpuv        1.5.2    2019-09-11 [1] CRAN (R 3.6.1)                   
 httr          1.4.1    2019-08-05 [1] CRAN (R 3.6.1)                   
 jsonlite      1.6.1    2020-02-02 [1] CRAN (R 3.6.2)                   
 later         1.0.0    2019-10-04 [1] CRAN (R 3.6.1)                   
 magick        2.3      2020-01-24 [1] CRAN (R 3.6.2)                   
 magrittr      1.5      2014-11-22 [1] CRAN (R 3.6.0)                   
 openssl       1.4.1    2019-07-18 [1] CRAN (R 3.6.1)                   
 processx      3.4.2    2020-02-09 [1] CRAN (R 3.6.2)                   
 promises      1.1.0    2019-10-04 [1] CRAN (R 3.6.1)                   
 ps            1.3.2    2020-02-13 [1] CRAN (R 3.6.2)                   
 R6            2.4.1    2019-11-12 [1] CRAN (R 3.6.1)                   
 rappdirs      0.3.1    2016-03-28 [1] CRAN (R 3.6.0)                   
 Rcpp          1.0.3    2019-11-08 [1] CRAN (R 3.6.1)                   
 RSelenium     1.7.7    2020-02-03 [1] CRAN (R 3.6.2)                   
 rtweet        0.7.0    2020-01-08 [1] CRAN (R 3.6.2)                   
 semver        0.2.0    2017-01-06 [1] CRAN (R 3.6.0)                   
 sessioninfo   1.1.1    2018-11-05 [1] CRAN (R 3.6.0)                   
 wdman         0.2.5    2020-01-31 [1] CRAN (R 3.6.2)                   
 withr         2.1.2    2018-03-15 [1] CRAN (R 3.6.0)                   
 XML           3.99-0.3 2020-01-20 [1] CRAN (R 3.6.2)                   
 xml2          1.2.2    2019-08-09 [1] CRAN (R 3.6.1)                   
 yaml          2.2.1    2020-02-01 [1] CRAN (R 3.6.2)                   

[1] C:/Program Files/R/R-3.6.2/library
> x <- carbon$new('x <- 1')
> x$carbonate()
starting chrome session...
checking chromedriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
Error in wdman::selenium(port = port, verbose = verbose, version = version,  : 
  Selenium server signals port = 32580 is already in use.

can you try this, just to see that the RSelenium wdman are connecting ok for you

port <- httpuv::randomPort()

cDrv <- wdman::chrome(port = port)

rD <- RSelenium::rsDriver(
  browser = "chrome",
  verbose = TRUE,
  chromever = 'latest',
  port = port,
  extraCapabilities = list(
    chromeOptions = list(args = c("--disable-gpu", "--window-size=1280,800"),
                         prefs = list(
                           "profile.default_content_settings.popups" = 0L,
                           "download.prompt_for_download" = FALSE,
                           "download.directory_upgrade" = TRUE,
                           "safebrowsing.enabled" = TRUE,
                           "download.default_directory" = tempdir()
                         ))
  )
)

rD$client$navigate('https://github.com')

# to close the browser
rD$client$close()

# to close the server
rD$server$stop()

# stop the chrome process
cDrv$stop()

It fails :

> port <- httpuv::randomPort()
> 
> cDrv <- wdman::chrome(port = port)
checking chromedriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
> 
> rD <- RSelenium::rsDriver(
+   browser = "chrome",
+   verbose = TRUE,
+   chromever = 'latest',
+   port = port,
+   extraCapabilities = list(
+     chromeOptions = list(args = c("--disable-gpu", "--window-size=1280,800"),
+                          prefs = list(
+                            "profile.default_content_settings.popups" = 0L,
+                            "download.prompt_for_download" = FALSE,
+                            "download.directory_upgrade" = TRUE,
+                            "safebrowsing.enabled" = TRUE,
+                            "download.default_directory" = tempdir()
+                          ))
+   )
+ )
checking Selenium Server versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking chromedriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking geckodriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking phantomjs versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
Error in wdman::selenium(port = port, verbose = verbose, version = version,  : 
  Selenium server signals port = 15544 is already in use.

ok.

so this issue is for @juyeongkim at RSelenium issues https://github.com/ropensci/RSelenium/issues

seems like the new version is not working well with winos.

thanks for trying that script, hopefully he can help.

httpuv is merged into the master. PR #22. carbonace may be a better alternative for you