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

Document keepalive for connections using the pool package [Lost connection to MySQL server during query [2013]] #358

Open
vituri opened this issue Apr 4, 2021 · 6 comments

Comments

@vituri
Copy link

vituri commented Apr 4, 2021

I am constantly getting the error Lost connection to MySQL server during query [2013], which seems to be related to the connection timeout. This happens when I create a con object and try to use it to collect a table after some time (say, 10 minutes). My connection is created using the command

con = 
RMariaDB::dbConnect(
      drv = RMariaDB::MariaDB(),
      username = username,
      password = password,
      host = host,
      port = port,
      dbname = dbname,
      timeout = -1
    )

I also tried to put "timeout = Inf" but with no success. Is the "timeout" argument really working? I am using the github version of DBI and RMariaDB packages.

@krlmlr
Copy link
Member

krlmlr commented Apr 4, 2021

Thanks. Is a connection timeout (=dropping of existing inactive connections) configured in the server?

@vituri
Copy link
Author

vituri commented Apr 4, 2021

Here are some of the variables in the server:

wait_timeout: 28800
connect_timeout: 10
idle_transaction_timeout: 0

I don't remember having this error before, and I didn't change the MariaDB (version 10.4.8) configurations since I start using it 8 months ago. What do you suggest?

@krlmlr
Copy link
Member

krlmlr commented Apr 5, 2021

Thanks, the timeouts look good to me. There's also interactive_timeout but it's only used with connections that set the CLIENT_INTERACTIVE flag.

Do the server logs give a hint on what's happening here?

@vituri
Copy link
Author

vituri commented May 13, 2021

I couldn't get the logs, but found a kind of solution using the "pool" package. It takes care of the connections (in case of several users connecting in a shinyapp) and keep sending small queries so the connection doesn't turn off. I just had to change the connector to

con =
    pool::dbPool(
      drv = RMariaDB::MariaDB(),
      username = username,
      password = password,
      host = host,
      port = port,
      dbname = dbname,
      validationInterval = 300
    )

@krlmlr
Copy link
Member

krlmlr commented May 14, 2021

This is a very neat trick, thanks for sharing!

@krlmlr krlmlr transferred this issue from r-dbi/RMariaDB Aug 29, 2021
@krlmlr krlmlr added the docs label Aug 29, 2021
@krlmlr
Copy link
Member

krlmlr commented Aug 29, 2021

Need to find a place where to document this trick.

@krlmlr krlmlr changed the title Lost connection to MySQL server during query [2013] Document keepalive for connections using the pool package [Lost connection to MySQL server during query [2013]] Aug 29, 2021
@krlmlr krlmlr added this to the 1.1.2 milestone Sep 14, 2021
@krlmlr krlmlr removed this from the 1.1.2 milestone Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants