How to set timeout in mysql c++ connector - c++

I am using c++ connector to connect to MySQL server. When server is offline or in sleep,the statement execute method takes a while to detect the connection problem.
Is there a method or variable to control the waiting timeout period in client?
Regards
Devara Gudda

You can use the mysql_options function to set the client timeout. Full details here... http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html

Related

gRPC timeout on server side

I'm working on bidirectional stream gRPC in C++. I want to set a timeout limit on server side, and kill the connection if it exceeds a threshold.
But the only timeout mechanism I've found is on client side(https://grpc.io/blog/deadlines/#c). And I don't find any API possible to for ServerContext(https://grpc.github.io/grpc/cpp/classgrpc_1_1_server_context.html). Does someone know how to do that?
gRPC does not support server side timeout limit/setting and hence you might need to have your own implementation mechanism and update client using context.abort.

gcp cloud sql proxy "wsarecv: An existing connection was forcibly closed by the remote host."

I have developed django with gcp cloud sql proxy not in trouble. But suddenly I can 't connect cloud sql with this message.
console message:
2019/03/15 11:48:41 Ready for new connections
2019/03/15 11:48:50 New connection for "my-project-instance"
2019/03/15 11:48:52 Reading data from local connection on 127.0.0.1:5432 had error: read tcp 127.0.0.1:5432->127.0.0.1:55125: wsarecv: An existing connection was forcibly closed by the remote host.
how can i fix this?
MySQL has a default wait_timeout value of 8 hours - any connections open for this length of time get forcibly closed.
You should use connection pooling (a great library for this in python is SQLAlchemy) and limit the connection duration to a value lower than this. You can see several examples of how to do this on the Managing Database Connections page.

Apache Thrift: Terminate Connection from the Server

I am using thrift to provide an interface between a device and a management console. It is possible for there to be up to 4 active connections to the device at one time, and I have this working using a TThreadPool server.
The issue arises around client disconnections; If a client disconnects correctly, there is no issue, however if one does not (i.e. the client crashes out or doesn't call client->close()) then the server seems to keep that clients thread alive. This means that when the next connection attempt is made, the client hangs, as the server has used up its allocated thread pool so cannot service the new request.
I haven't been able to find any standard, public mechanism by which the server can stop, and hence free up, a clients thread if that client has not used the interface for a set time period?
Is there a standard way to facilitate this in thrift?
Set the receive/send timeout on the server socket might help. Server will close the connection on timeout.
https://github.com/apache/thrift/blob/129f332d72facda5d06f87e2b4e5e08bea0b6b44/lib/cpp/src/thrift/transport/TServerSocket.h#L103
void setSendTimeout(int sendTimeout);
void setRecvTimeout(int recvTimeout);

Winsock select function returning different values

I am working on project having client server architecture. select function returns different value in different scenarios Followings are the details
Scenario 1:
When i install my server at my machine, stop all the corresponding services, my client goes to DC state and now return value of select is 1 and read_mask.fd_count is also 1.
Scenario 2:
When i connect to remote server (abc.com) and disconnect my wireless connection. in this case the same function returns 0 also read_mask.fd_count is 0. i tried changing timeout variable value from ten ms to 50 sec. cant figure out the problem.
Any help will be appreciated
When you shot down the server you cause the network stack to shutdown the connection. Furtehr connection request are refused. The select indicates that there's something and the the recv() returns 0 to indicate forcibly closed.
When you pull the wireless cable out of the plug then the client gets neither the shutdown nor the connection request. You wait for any timeout to detect the not available server.
In a real world application you should implement a kind of heartbeat in you protocol that allows to detect the "disconnected state" in the second scenario.
Edit: If your Winsock implementation supports SO_KEEPALIVE_VALS, you can also configure this to detect the lost connectivity. See also: SO_KEEPALIVE.

ActiveMQCPP connection.start() hangs up

I'm using ActiveMQ CPP 5.2.3 if it matters.
I have JMS producer that connects using failover transport to JMS network of brokers.
When I call connection->start() it hangs up (see AMQ-2114).
If I skip connection start() and call connection->createSession(), than this call is blocked too.
The requirement is that my application will try forever to connect to broker(s).
Any suggestions/workarounds?
NOTE:
This is not duplicate of here, since I'm talking about C++ and such solutions as embedded broker, spring are not available in C++.
This is normal when the connection is awaiting a transport to connect to the broker. The start method must send the client's id info to the broker before any other operation, so if no connection is present it must block. You can set some options on the failover transport like the startupMaxReconnectAttempts option to control how long it will try to connect before reporting a failure. See the URI configuration page:
http://activemq.apache.org/cms/configuring.html