Bad token incorrectly results in socket timeout
Closed this issue · 1 comments
Running binary network protocol on orientdb server 2.0.5, storing server token on client and re-using it for multiple requests works fine. However, if enough time elapses (15 minutes I think but can't be sure) between server requests then token expires and orientdb server does not return a message and close the connection. Instead, the socket_read just hangs and eventually times out. In testing, I can get the same thing to happen if I append a character to the end of a valid token like this:
$this->db = new PhpOrient(env('orientDB_HOST'),2424, $orientdbSessionToken . 'a');
$this->db->query("select from V limit 10");
Expected behavior: when token expires or server receives unrecognized token then it should return an error message and close the connection.
I filed this issue with the OrientDB team and they said the server is correctly responding with a bad token message but that the php driver isn't picking it up. Luca asked me to submit the issue here. Thanks
Hi @dcarr178 ,
i tried to reproduce your issue on OrientDB version 2.0.4 and 2.08, but you're right, the server does not return any message and close the connection.
Tried with this simple script:
$client = new PhpOrient( 'localhost', 2424 );
$client->setSessionToken( true ); // set true to enable the token based authentication
$clusterID = $client->dbOpen( "GratefulDeadConcerts", 'admin', 'admin' );
$sessionToken = $client->getSessionToken(); // store this token somewhere
file_put_contents( "token.bin", $sessionToken );
and after
$sessionToken = file_get_contents( "token.bin" );
// start a new connection
$client = new PhpOrient( 'localhost', 2424 );
// set the previous received token to re-attach to the old session with a wrong token
$client->setSessionToken( $sessionToken . "WRONG_TOKEN" );
//now the dbOpen is not needed but the server close the connection before the client can read the response header
$records = $client->query( 'select * from V limit 10' );
This is the server log:
2015-04-19 00:00:18:775 INFO /127.0.0.1:33621 - Reading byte (1 byte)... [OChannelBinaryServer]
2015-04-19 00:01:37:531 INFO /127.0.0.1:33624 - Connected [OChannelBinaryServer]
2015-04-19 00:01:37:531 INFO /127.0.0.1:33624 - Writing short (2 bytes): 28 [OChannelBinaryServer]
2015-04-19 00:01:37:531 INFO /127.0.0.1:33624 - Flush [OChannelBinaryServer]
2015-04-19 00:01:37:532 INFO /127.0.0.1:33624 - Reading byte (1 byte)... [OChannelBinaryServer]
2015-04-19 00:04:54:515 INFO /127.0.0.1:33624 - Read byte: 41 [OChannelBinaryServer]
2015-04-19 00:04:54:516 INFO /127.0.0.1:33624 - Reading int (4 bytes)... [OChannelBinaryServer]
2015-04-19 00:04:54:517 INFO /127.0.0.1:33624 - Read int: -1 [OChannelBinaryServer]
2015-04-19 00:04:54:518 INFO /127.0.0.1:33624 - Reading chunk of bytes. Reading chunk length as int (4 bytes)... [OChannelBinaryServer]
2015-04-19 00:04:54:519 INFO /127.0.0.1:33624 - Read chunk lenght: 155 [OChannelBinaryServer]
2015-04-19 00:04:54:520 INFO /127.0.0.1:33624 - Reading 155 bytes... [OChannelBinaryServer]
2015-04-19 00:04:54:521 INFO /127.0.0.1:33624 - Read 155 bytes: GratefulDeadConcertsL��ڲORecordDocument2csv*PhpOrient - PHP binary client for OrientDBv1.1.2]�]�a�G=���s��pS{y,���WRONG_TOKEN [OChannelBinaryServer]
2015-04-19 00:04:54:524 INFO /127.0.0.1:33624 - Flush [OChannelBinaryServer]
2015-04-19 00:04:54:526 INFO /127.0.0.1:33624 - Closing socket... [OChannelBinaryServer]
I tried to set the token lifetime to 2 minutes ( default is 60 minutes, it can be changed in config/orientdb-server-config.xml ) to try the renew procedure but the server does the same thing instead to send a new fresh token.
I will report the bug to OrientDB team.
I added an exception in that case in PhpOrient:
"socket_read(): unable to read from socket [104]: Connection reset by peer"