Added session timeouts.
The parameter 'connection_timeout' for services takes a value as seconds. All sessions that have been idle for longer than this will be disconnected.
This commit is contained in:
@ -40,6 +40,7 @@
|
||||
* internal router suppression of messages
|
||||
* 30/10/14 Massimiliano Pinto Added disable_master_failback parameter
|
||||
* 07/11/14 Massimiliano Pinto Addition of monitor timeouts for connect/read/write
|
||||
* 20/02/15 Markus Mäkelä Added connection_timeout parameter for services
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -278,6 +279,7 @@ int error_count = 0;
|
||||
char *user;
|
||||
char *auth;
|
||||
char *enable_root_user;
|
||||
char *connection_timeout;
|
||||
char *weightby;
|
||||
char *version_string;
|
||||
bool is_rwsplit = false;
|
||||
@ -288,6 +290,9 @@ int error_count = 0;
|
||||
enable_root_user = config_get_value(
|
||||
obj->parameters,
|
||||
"enable_root_user");
|
||||
connection_timeout = config_get_value(
|
||||
obj->parameters,
|
||||
"connection_timeout");
|
||||
weightby = config_get_value(obj->parameters, "weightby");
|
||||
|
||||
version_string = config_get_value(obj->parameters,
|
||||
@ -332,6 +337,11 @@ int error_count = 0;
|
||||
serviceEnableRootUser(
|
||||
obj->element,
|
||||
config_truth_value(enable_root_user));
|
||||
if (connection_timeout)
|
||||
serviceSetTimeout(
|
||||
obj->element,
|
||||
atoi(connection_timeout));
|
||||
|
||||
if (weightby)
|
||||
serviceWeightBy(obj->element, weightby);
|
||||
|
||||
@ -1281,13 +1291,15 @@ SERVER *server;
|
||||
char *user;
|
||||
char *auth;
|
||||
char *enable_root_user;
|
||||
char *connection_timeout;
|
||||
char* max_slave_conn_str;
|
||||
char* max_slave_rlag_str;
|
||||
char *version_string;
|
||||
char *allow_localhost_match_wildcard_host;
|
||||
|
||||
enable_root_user = config_get_value(obj->parameters, "enable_root_user");
|
||||
|
||||
connection_timeout = config_get_value(obj->parameters, "connection_timeout");
|
||||
|
||||
user = config_get_value(obj->parameters,
|
||||
"user");
|
||||
auth = config_get_value(obj->parameters,
|
||||
@ -1310,6 +1322,8 @@ SERVER *server;
|
||||
auth);
|
||||
if (enable_root_user)
|
||||
serviceEnableRootUser(service, atoi(enable_root_user));
|
||||
if (connection_timeout)
|
||||
serviceSetTimeout(service, atoi(connection_timeout));
|
||||
|
||||
if (allow_localhost_match_wildcard_host)
|
||||
serviceEnableLocalhostMatchWildcardHost(
|
||||
@ -1415,11 +1429,17 @@ SERVER *server;
|
||||
char *user;
|
||||
char *auth;
|
||||
char *enable_root_user;
|
||||
char *connection_timeout;
|
||||
char *allow_localhost_match_wildcard_host;
|
||||
|
||||
enable_root_user =
|
||||
config_get_value(obj->parameters,
|
||||
"enable_root_user");
|
||||
|
||||
connection_timeout =
|
||||
config_get_value(obj->parameters,
|
||||
"connection_timeout");
|
||||
|
||||
allow_localhost_match_wildcard_host =
|
||||
config_get_value(obj->parameters, "localhost_match_wildcard_host");
|
||||
|
||||
@ -1438,6 +1458,9 @@ SERVER *server;
|
||||
if (enable_root_user)
|
||||
serviceEnableRootUser(obj->element, atoi(enable_root_user));
|
||||
|
||||
if (connection_timeout)
|
||||
serviceSetTimeout(obj->element, atoi(connection_timeout));
|
||||
|
||||
if (allow_localhost_match_wildcard_host)
|
||||
serviceEnableLocalhostMatchWildcardHost(
|
||||
obj->element,
|
||||
@ -1661,6 +1684,7 @@ static char *service_params[] =
|
||||
"user",
|
||||
"passwd",
|
||||
"enable_root_user",
|
||||
"connection_timeout",
|
||||
"localhost_match_wildcard_host",
|
||||
"max_slave_connections",
|
||||
"max_slave_replication_lag",
|
||||
|
||||
@ -57,6 +57,7 @@
|
||||
#include <log_manager.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <housekeeper.h>
|
||||
|
||||
/** Defined in log_manager.cc */
|
||||
extern int lm_enabled_logfiles_bitmask;
|
||||
@ -431,6 +432,8 @@ int listeners = 0;
|
||||
service->stats.started = time(0);
|
||||
}
|
||||
|
||||
hktask_add("connection_timeout",session_close_timeouts,NULL,5);
|
||||
|
||||
return listeners;
|
||||
}
|
||||
|
||||
@ -803,6 +806,23 @@ serviceEnableRootUser(SERVICE *service, int action)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the session timeout for the service.
|
||||
* @param service Service to configure
|
||||
* @param val Timeout in seconds
|
||||
* @return 1 on success, 0 when the value is invalid
|
||||
*/
|
||||
int
|
||||
serviceSetTimeout(SERVICE *service, int val)
|
||||
{
|
||||
|
||||
if(val < 0)
|
||||
return 0;
|
||||
service->conn_timeout = val;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim whitespace from the from an rear of a string
|
||||
*
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
#include <atomic.h>
|
||||
#include <skygw_utils.h>
|
||||
#include <log_manager.h>
|
||||
#include <housekeeper.h>
|
||||
|
||||
/** Defined in log_manager.cc */
|
||||
extern int lm_enabled_logfiles_bitmask;
|
||||
@ -909,3 +910,35 @@ SESSION *get_all_sessions()
|
||||
{
|
||||
return allSessions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close sessions that have been idle for too long.
|
||||
*
|
||||
* If the time since a session last sent data is grater than the set value in the
|
||||
* service, it is disconnected. The default value for the timeout for a service is 0.
|
||||
* This means that connections are never timed out.
|
||||
* @param data NULL, this is only here to satisfy the housekeeper function requirements.
|
||||
*/
|
||||
void session_close_timeouts(void* data)
|
||||
{
|
||||
SESSION* ses;
|
||||
|
||||
spinlock_acquire(&session_spin);
|
||||
ses = get_all_sessions();
|
||||
spinlock_release(&session_spin);
|
||||
|
||||
while(ses)
|
||||
{
|
||||
if(ses->client && ses->client->state == DCB_STATE_POLLING &&
|
||||
ses->service->conn_timeout > 0 &&
|
||||
hkheartbeat - ses->client->last_read > ses->service->conn_timeout * 10)
|
||||
{
|
||||
ses->client->func.hangup(ses->client);
|
||||
}
|
||||
|
||||
spinlock_acquire(&session_spin);
|
||||
ses = ses->next;
|
||||
spinlock_release(&session_spin);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user