wvanbergen / node-vertica

Pure javascript Vertica database client. Except it is written in CoffeeScript.
MIT License
44 stars 30 forks source link

How do you end a connection/disconnect without getting the 'unexpected EOF' message in the server log? #47

Closed kimwykoff closed 9 years ago

kimwykoff commented 9 years ago

Hi,

I'm using node-vertica version 0.5.2 and Vertica Analytic Database v7.1.1-0. I'm facing an issue where when I call disconnect(), I always see this message in the server log:

Unexpected EOF on client connection

I'm simply executing a query and then disconnecting:

var   vertica = require('vertica')
var _ = require('lodash')

var verticaSettings = {
    "port": 5433,
    "user": "dbuser",
    "password": "dbpass",
    "database": "verticaDB",
    "schema": "dbschema",
    "host": "192.168.249.211"
}

vertica.connect(verticaSettings, function (err, conn) {
    if (err) {
        console.log('connection error', err)
    } else {
        queryVertica("select count(*) from sessions", conn, function(err, results) {
            console.log('err = ', err)
            console.log('results = ', results)
            conn.connection.end()
            conn.disconnect()
        })
    }
})
function queryVertica(query, connection, asyncCallback) {
    var myQuery = connection.query(query, function (err, resultSet) {
        if (err) {
            console.log('query error', err)
        }
    })

    var fieldsArray = [];
    var rows = [];
    var index = 0;
    myQuery.on('fields', function (fields) {
        fieldsArray = fields;
        ;
    });
    myQuery.on('row', function (row) {
        var columns = _.pluck(fieldsArray, 'name')
        rows[index] = _.zipObject(columns, row);
        index++;
    });
    myQuery.on('end', function (status) {
        console.log("status:", status);
        asyncCallback(null, rows)
    });
    myQuery.on('error', function (err) {
        console.log('err', err);
        asyncCallback(errorMsg);
    });
}

When I run that, I see this in the vertica server log:

57.215 Init Session:0x7fed340116b0 <LOG> @v_verticadb_node0001: 00000/2705: Connection received: host=192.168.249.1 port=52981 (connCnt 3)
57.217 Init Session:0x7fed340116b0 <LOG> @v_verticadb_node0001: 00000/4540: Received SSL negotiation startup packet
57.217 Init Session:0x7fed340116b0 <LOG> @v_verticadb_node0001: 00000/4691: Sending SSL negotiation response 'N'
57.223 Init Session:0x7fed340116b0 <LOG> @v_verticadb_node0001: 00000/4686: Authentication - sendAuthRequest: user=dbuser database=verticaDB host=192.168.249.1 authType=3
57.225 Init Session:0x7fed340116b0-a0000000000359 [Txn] <INFO> Begin Txn: a0000000000359 'check_login_history'
57.226 Init Session:0x7fed340116b0-a0000000000359 [Txn] <INFO> Rollback Txn: a0000000000359 'check_login_history'
57.226 Init Session:0x7fed340116b0 <LOG> @v_verticadb_node0001: 00000/4686: Authentication - sendAuthRequest: user=dbuser database=verticaDB host=192.168.249.1 authType=0
57.226 Init Session:0x7fed340116b0 <LOG> @v_verticadb_node0001: 00000/2703: Connection authenticated: user=dbuser database=verticaDB host=192.168.249.1
57.229 Init Session:0x7fed340116b0 [Session] <INFO> [Query] TX:0(iod-vertica-1-20028:0x194a) select count(*) from sessions
57.231 Init Session:0x7fed340116b0-a000000000035a [Txn] <INFO> Begin Txn: a000000000035a 'select count(*) from sessions'
57.266 Init Session:0x7fed340116b0-a000000000035a <LOG> @v_verticadb_node0001: 08006/5167: Unexpected EOF on client connection
57.266 Init Session:0x7fed340116b0-a000000000035a <LOG> @v_verticadb_node0001: 00000/4719: Session iod-vertica-1-20028:0x194a ended; closing connection (connCnt 3)
57.266 Init Session:0x7fed340116b0-a000000000035a [Txn] <INFO> Rollback Txn: a000000000035a 'select count(*) from sessions'

I don't know how to end a session before I disconnect so that I get rid of this message. I've tried putting a 'rollback' after the select, but I get the same message.

I've also tried making the connection interruptible and calling sessionInterrupt(), but I still get the same Unexpected EOF message.

Does anyone know how to end the connection gracefully? We're using this with generic-pool, so we're doing lots of disconnections and getting this messages a ton in the log. Thanks!

wvanbergen commented 9 years ago

I see you're doing

conn.connection.end()
conn.disconnect()

disconnect() will call connection.end() for you, after sending the "close connection" message top the server. So you can simply remove the conn.connection.end() call

kimwykoff commented 9 years ago

Sorry, I shouldn't have left that in - it was just me fiddling around. I still get the problem even if I don't call end(). So I would like to re-open this issue, but I don't know how.

With just the

conn.disconnect()

, the log file still indicates an Unexpected EOF:

8:17.729 Init Session:0x7fed34014010 <LOG> @v_verticadb_node0001: 00000/2705: Connection received: host=192.168.249.1 port=51740 (connCnt 3)
8:17.730 Init Session:0x7fed34014010 <LOG> @v_verticadb_node0001: 00000/4540: Received SSL negotiation startup packet
8:17.730 Init Session:0x7fed34014010 <LOG> @v_verticadb_node0001: 00000/4691: Sending SSL negotiation response 'N'
8:17.733 Init Session:0x7fed34014010 <LOG> @v_verticadb_node0001: 00000/4686: Authentication - sendAuthRequest: user=dbUser database=verticaDB host=192.168.249.1 authType=3
8:17.735 Init Session:0x7fed34014010-a0000000006308 [Txn] <INFO> Begin Txn: a0000000006308 'check_login_history'
8:17.735 Init Session:0x7fed34014010-a0000000006308 [Txn] <INFO> Rollback Txn: a0000000006308 'check_login_history'
8:17.735 Init Session:0x7fed34014010 <LOG> @v_verticadb_node0001: 00000/4686: Authentication - sendAuthRequest: user=dbUser database=verticaDB host=192.168.249.1 authType=0
8:17.735 Init Session:0x7fed34014010 <LOG> @v_verticadb_node0001: 00000/2703: Connection authenticated: user=dbUser database=verticaDB host=192.168.249.1
8:17.737 Init Session:0x7fed34014010 [Session] <INFO> [Query] TX:0(iod-vertica-1-20028:0x36fdd) select count(*) from sessions
8:17.738 Init Session:0x7fed34014010-a0000000006309 [Txn] <INFO> Begin Txn: a0000000006309 'select count(*) from sessions'
8:17.785 Init Session:0x7fed34014010-a0000000006309 <LOG> @v_verticadb_node0001: 08006/5167: Unexpected EOF on client connection
8:17.785 Init Session:0x7fed34014010-a0000000006309 <LOG> @v_verticadb_node0001: 00000/4719: Session iod-vertica-1-20028:0x36fdd ended; closing connection (connCnt 3)
8:17.785 Init Session:0x7fed34014010-a0000000006309 [Txn] <INFO> Rollback Txn: a0000000006309 'select count(*) from sessions'
kimwykoff commented 9 years ago

BTW, I noticed that vertica provides the finish() method in their odbc driver and if finish() is called from perl, then there is no 'Unexpected EOF' message:

$query = "SELECT distinct Calendar_Month_Name FROM Date_Dimension";
$sth = $dbh->prepare($query);
$sth->execute();

# Bind the variables and then look throuhg the results

$sth->bind_columns(undef, \$month );

while($sth->fetch())
   {
   print "$month\n"
   }
# Disconnect from the database
$sth->finish;
$dbh->disconnect
or warn "Disconnection failed: $DBI::errstr\n";
exit;

I couldn't find a 'finish' call in the node-vertica module.