1

I am using MySQL in tandem with nanomsg in my C application. nanomsg is creating some tcp connections to remote servers, while MySQL is connecting to a localhost database.

I am porting from SQLite, and don't have as much experience with MySQL, so please excuse me if this is trivial.

MySQL seems to work fine, creating the db on init. and inserting some records. However, when I start the tcp connection on nanomsg, I get:

Lost connection to MySQL server during query
MySQL server has gone away

If I don't create the thread that polls my remote tcp connection, it still does this. This is what is causing MySQL to lose its connection:

    const char *endpoint            = "tcp://xx.xxx.xxx.xx:3000";
    int timeout = 5;
    int sock = nn_socket (AF_SP, NN_PAIR);
    assert (sock >= 0);
    assert (nn_connect (sock, endpoint) >= 0);
    assert (nn_setsockopt (sock, NN_SOL_SOCKET, NN_RCVTIMEO, &to, sizeof (to)) >= 0);
    assert (nn_setsockopt (sock, NN_SOL_SOCKET, NN_SNDTIMEO, &to, sizeof (to)) >= 0);

I tried to raise the read timeout in MySQL, but it didn't work.

int MYSQlTimeout = 6000;
mysql_options(mysqldb,MYSQL_OPT_READ_TIMEOUT,&MYSQlTimeout);

I also tried adding mysqld to /etc/hosts.allow mysqld: 127.0.0.1

Still doesn't work.

Any help would be greatly appreciated.

Matthew Darnell
  • 1,315
  • 2
  • 12
  • 24
  • 1
    I continued to rebuild the application and try it, it eventually worked. It also is working with all 3 separate tcp connections now. I have no idea why, I changed nothing. I'm worried this issue will crop back up, especially once I push to the production server. – Matthew Darnell Dec 28 '15 at 01:00
  • Well, it seems to be working still. I'll keep monitoring it. It did lose connection again, but I set some options which seemed to help: mysql_options(mysqldb,MYSQL_OPT_READ_TIMEOUT,&MYSQlTimeout); mysql_options(mysqldb, MYSQL_OPT_RECONNECT, &MYSQLReconnect); where MYSQLTimeout is a large integer and MYSQLReconnect = 1 – Matthew Darnell Dec 28 '15 at 05:52

0 Answers0