Skip to content

Adding timeout configuration for read and write queries #203

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

Closed
wants to merge 343 commits into from

Conversation

raggaraluz
Copy link

I've found that the issue #190 is happening due to a bug in mariadb connector 2.3.2, making it fail if timeout is not explicitely set. (see mariadb-corporation/mariadb-connector-c@42d6d3f for details).

The solution I created was to add a timeout option to the connection creation, so that the timeout is set and #190 is not happening anymore.

I assume that the issue could also be fixed by updateing to mariadb connector 2.3.3, but having a timeout configuration is useful anyway to avoid long-running queries not to finish.

jeroen and others added 30 commits February 23, 2015 15:42
Replace isnan() with R's ISNAN(), as described in Writing R Extensions:

> Functions/macros such as isnan, isinf and isfinite are not required by
> C++98: where compilers support them they may be only in the std
> namespace or only in the main namespace. There is no way to make use
> of these functions which works with all C++ compilers currently in use
> on R platforms: use R’s versions such as ISNAN and R_FINITE instead.
> -- [R Core Team,Writing R Extensions: Portable C and C++ code]
> (https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Portable-C-and-C_002b_002b-code)

This prevents the following error when trying to build RMySQL on my
Mac OS X 10.7:

    MyBinding.h:100: error: ‘isnan’ was not declared in this scope

Further reading:
* https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Portable-C-and-C_002b_002b-code
* https://stat.ethz.ch/pipermail/r-devel/2005-January/thread.html#31793
* https://stat.ethz.ch/pipermail/r-devel/2005-January/thread.html#31800
* http://lists.apple.com/archives/Xcode-users/2006/Aug/thrd7.html#00619
* http://lists.apple.com/archives/Xcode-users/2006/Aug/thrd7.html#00633
* http://stackoverflow.com/questions/18128899/is-isnan-in-the-std-namespace-more-in-general-when-is-std-necessary-optio
* http://stackoverflow.com/questions/2249110/how-do-i-make-a-portable-isnan-isinf-function
* http://stackoverflow.com/questions/570669/checking-if-a-double-or-float-is-nan-in-c
Use ISNAN() to prevent build error on OS X 10.7
Copy link
Member

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into it. Can you please provide more detail about how your patch solves #190?

@@ -31,12 +31,16 @@ class MyConnection : boost::noncopyable {
const Rcpp::Nullable<std::string>& ssl_cert,
const Rcpp::Nullable<std::string>& ssl_ca,
const Rcpp::Nullable<std::string>& ssl_capath,
const Rcpp::Nullable<std::string>& ssl_cipher) :
const Rcpp::Nullable<std::string>& ssl_cipher,
unsigned int timeout) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indention looks odd here and below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, maybe my editor mixed it up. I can fix it.

R/connect.R Outdated
@@ -62,11 +63,11 @@ setMethod("dbConnect", "MySQLDriver",
function(drv, dbname = NULL, username = NULL, password = NULL, host = NULL,
unix.socket = NULL, port = 0, client.flag = 0,
groups = "rs-dbi", default.file = NULL, ssl.key = NULL, ssl.cert = NULL,
ssl.ca = NULL, ssl.capath = NULL, ssl.cipher = NULL, ...) {
ssl.ca = NULL, ssl.capath = NULL, ssl.cipher = NULL, timeout=3600, ...) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale behind choosing a timeout of one hour?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to set a default value so high that queries are not being time-out in general. This is the behaviour I would expect if a timeout is not set.

In anyone wants to time-out the queries with a lower value, it can be set manually.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, if you find any other default value is better, I have no problem with that.

@raggaraluz
Copy link
Author

Hi Kirill,

The issue is that if no timeout is set to the mysql connection in the C driver, it is behaving as it was set to a very low value. Any query taking more than 1 second is being dropped by the driver.

Setting the timeout to a higher value, fixes the issue.

I'm not sure, but maybe it is related to this bug in mariadb connector: mariadb-corporation/mariadb-connector-c@42d6d3f so an alternative may be to upgrade to the latest version of mariadb.

@raggaraluz
Copy link
Author

This is not required after fix of #190

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants