Hello, Alan!
You wrote  on Wed, 21 Mar 2007 12:57:46 +0100:

After Nicolas Baradakis's patch some things changed. Now I know that if 
connection to PostgreSQL DB became broken, libpq does not free 
pg_sock->conn, so PQfinish(pg_sock->conn) MUST be called.

AD>   If pg_sock->conn is freed, that pointer MUST be set to NULL.

Yes, I understand that.

AD>   No.  sqlsocket->state is redundant.  If the "conn" handle exists,
AD> it
AD> MUST be a valid connection handle.  If it's not valid, it's NULL,
AD> and
AD> therefore the socket is disconnected.

Then each time sql_destroy_socket MUST be called after sql_close in database 
drivers and especially in sql_init_socket when DB connection can't be 
established. Of course, sqlsocket->state MUST be set then too, maybe in 
sql_destroy_socket function. It concerns all SQL drivers.

>> In theory, sqlsocket->state can equals to sockconnected when actually
>> it is disconnected.

I make some additional tests. When DB connection suddenly breakes, 
sqlsocket->state == sockconnected.

AD>   That's a bug.  It's wrong and MUST be fixed.

It seemes to me it would be hard to do. The simplest way I see is to use 
instead of sqlsocket->state a function that is declared in sql driver 
module. For PostgreSQL it may look so:

static int IsConnected(SQLSOCK *sqlsocket);
    rlm_sql_postgres_sock *pg_sock;

    if (sqlsocket->conn != NULL) {
        pg_sock = sqlsocket->conn;
        if ((pg_sock->conn != NULL) &&
         (PQstatus(pg_sock->conn) == CONNECTION_OK)) {
            return -1;
        else {
            return 0;
    else return 0;

It seemes to me, it's almost impossible to write code which will allow 
sqlsocket->conn to provide accurate information about connection state. But 
again, I'm not a programmer.

With best regards, Alexander V. Klepikov.  E-mail: [EMAIL PROTECTED] 

List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html

Reply via email to