hedgedandlevered
hedgedandlevered

Reputation: 2394

'Failed to connect: no buffer space' when curlPerform attempted

I'm sending a curlPerform with curl.opts set to

curl.opts = curlOptions(
  httpheader = c(
    'Content-Type'    = "application/x-www-form-urlencoded; charset=UTF-8",
    'Accept'          = "application/json"
  ),
  verbose = FALSE,
  header = TRUE,
  useragent = "RCurl"    
) 

and I eventually get the error "failed to connect to 192.168.141.136: no buffer space". I need to run this program constantly for days but this happens after about 6 minutes. Is there a way to set the buffer maximum higher? Alternatively, is there a way to view how much "buffer space" is remaining? If so I can set it to restart R and resume the program. Note that this happens if the program runs for a while, stops, and I manually restart it. The "buffer" is never being cleared. The only way to clear it that I've found is to restart R.

If it helps, I also lose my "connection" with Rstudio, even if I'm just doing this with a separate R window, and I also lose my connection to the internet after getting this error until I close R

edit: here is a partial result of traceback() (the rest isn't a problem)

11: fun(structure(list(message = msg, call = sys.call()), class = c(typeName, 
        "GenericCurlError", "error", "condition")))
10: function (type, msg, asError = TRUE) 
    {
        if (!is.character(type)) {
            i = match(type, CURLcodeValues)
            typeName = if (is.na(i)) 
                character()
            else names(CURLcodeValues)[i]
        }
        typeName = gsub("^CURLE_", "", typeName)
        fun = (if (asError) 
            stop
        else warning)
        fun(structure(list(message = msg, call = sys.call()), class = c(typeName, 
            "GenericCurlError", "error", "condition")))
    }(7L, "Failed to connect to 192.168.141.136: No buffer space", 
        TRUE)
9: .Call("R_curl_easy_perform", curl, .opts, isProtected, .encoding, 
       PACKAGE = "RCurl")
8: curlPerform(url = "http://gt-tradeview/House/TradeView/ajax/varys", 
       postfields = mkURL(parameters), .opts = curl.opts, writefunction = r$update, 
       post = 1L, curl = r$curl()) at functiondefinitionsLive.R#211
7: value[[3L]](cond)
6: tryCatchOne(expr, names, parentenv, handlers[[1L]])
5: tryCatchList(expr, classes, parentenv, handlers)

Upvotes: 0

Views: 1678

Answers (2)

hedgedandlevered
hedgedandlevered

Reputation: 2394

The problem was that handles were being reserved with every call, and never closed. To prevent this, get a curl handle with getCurlHandle() then pass that with the curl argument in dynCurlReader()

Upvotes: 1

Anant Gupta
Anant Gupta

Reputation: 1149

I was having the same issues with the getURL command. I tried CloseAllConnections() but that did not seem to work.

When I restarted the R session then the issue was resolved automatically. However, I have to admit that I got the issue when my RStudio ( R Session ) was opened for a long time. Might be some memory usage that an empty R Session does

Upvotes: 0

Related Questions