# connection (per_socket)
connect_failure_retry_delay = 60
+ # lifetime of an SQL socket. If you are having network issues
+ # such as TCP sessions expiring, you may need to set the socket
+ # lifetime. If set to non-zero, any open connections will be
+ # closed "lifetime" seconds after they were first opened.
+ lifetime = 0
+
+
# Set to 'yes' to read radius clients from the database ('nas' table)
# Clients will ONLY be read on server startup. For performance
# and security reasons, finding clients via SQL queries CANNOT
offsetof(SQL_CONFIG,deletestalesessions), NULL, "yes"},
{"num_sql_socks", PW_TYPE_INTEGER,
offsetof(SQL_CONFIG,num_sql_socks), NULL, "5"},
+ {"lifetime", PW_TYPE_INTEGER,
+ offsetof(SQL_CONFIG,lifetime), NULL, "0"},
{"sql_user_name", PW_TYPE_STRING_PTR,
offsetof(SQL_CONFIG,query_user), NULL, ""},
{"default_user_profile", PW_TYPE_STRING_PTR,
int rcode;
radlog(L_DBG, "rlm_sql (%s): Attempting to connect %s #%d",
inst->config->xlat_name, inst->module->name, sqlsocket->id);
-
rcode = (inst->module->sql_init_socket)(sqlsocket, inst->config);
if (rcode == 0) {
radlog(L_DBG, "rlm_sql (%s): Connected new DB handle, #%d",
inst->config->xlat_name, sqlsocket->id);
sqlsocket->state = sockconnected;
+ if (inst->config->lifetime) time(&sqlsocket->connected);
return(0);
}
SQLSOCK *cur, *start;
int tried_to_connect = 0;
int unconnected = 0;
- time_t now;
+ time_t now = time(NULL);
/*
* Start at the last place we left off.
#endif
/*
+ * If the socket has outlived its lifetime, and
+ * is connected, close it, and mark it as open for
+ * reconnections.
+ */
+ if (inst->config->lifetime && (cur->state == sockconnected) &&
+ ((cur->connected + inst->config->lifetime) < now)) {
+ (inst->module->sql_close)(cur, inst->config);
+ cur->state = sockunconnected;
+ goto reconnect;
+ }
+
+ /*
* If we happen upon an unconnected socket, and
* this instance's grace period on
* (re)connecting has expired, then try to
* connect it. This should be really rare.
*/
- if ((cur->state == sockunconnected) && (time(NULL) > inst->connect_after)) {
+ if ((cur->state == sockunconnected) && (now > inst->connect_after)) {
+ reconnect:
radlog(L_INFO, "rlm_sql (%s): Trying to (re)connect unconnected handle %d..", inst->config->xlat_name, cur->id);
tried_to_connect++;
connect_single_socket(cur, inst);
* This code has race conditions when threaded, but the
* only result is that a few more messages are logged.
*/
- now = time(NULL);
if (now <= last_logged_failure) return NULL;
last_logged_failure = now;