简体   繁体   中英

Node.js cassandra connection timeout

I'm receiving a timeout on connection to cassandra instance using Node js Cassandra version: 3.9 Node js: v6.9.1 I'm connecting using this driver: https://github.com/datastax/nodejs-driver

Here is my code snippet:

const express = require('express');
const cassandra = require('cassandra-driver');
const async = require('async');

// Constants
const PORT = 8080;
const CASSANDRA_PORT = process.env['CASSANDRA_PORT'];
const CASSANDRA_PATH = '127.0.0.1';

// App
const app = express();
app.set('view engine', 'pug');
app.set('views', './views');

var client = new cassandra.Client({contactPoints: [CASSANDRA_PATH], protocolOptions: {port: CASSANDRA_PORT}});

client.on('log', function(level, className, message, furtherInfo) {
  console.log('log event: %s -- %s', level, message);
});

client.connect(function (e, m) {
  console.log(e);
  console.log(m);
});

Error stacktrace:

log event: info -- Adding host 127.0.0.1:7000
log event: info -- Getting first connection
log event: info -- Connecting to 127.0.0.1:7000
log event: verbose -- Socket connected to 127.0.0.1:7000
log event: info -- Trying to use protocol version 4
log event: verbose -- Sending stream #0
log event: verbose -- Sent stream #0 to 127.0.0.1:7000
log event: info -- Connection to 127.0.0.1:7000 closed
log event: warning -- There was an error when trying to connect to the host 127.0.0.1
log event: warning -- Connection to 127.0.0.1:7000 could not be created: OperationTimedOutError: The host 127.0.0.1:7000 did not reply before timeout 12000 ms
log event: warning -- Connection pool to host 127.0.0.1:7000 could not be created
{ [Error: All host(s) tried for query failed. First host tried, 127.0.0.1:7000: OperationTimedOutError: The host 127.0.0.1:7000 did not reply before timeout 12000 ms. See innerErrors.]
  innerErrors: 
   { '127.0.0.1:7000': 
      { Error: The host 127.0.0.1:7000 did not reply before timeout 12000 ms
          at OperationTimedOutError.DriverError (
        message: 'The host 127.0.0.1:7000 did not reply before timeout 12000 ms',
        info: 'Represents a client-side error that is raised when the client did not hear back from the server within socketOptions.readTimeout' } },
  info: 'Represents an error when a query cannot be performed because no host is available or could be reached by the driver.',
  message: 'All host(s) tried for query failed. First host tried, 127.0.0.1:7000: OperationTimedOutError: The host 127.0.0.1:7000 did not reply before timeout 12000 ms. See innerErrors.' }
undefined

FYI, Keyspace is created in advance. How can I avoid this timeout exception during server start?

It looks like you are connecting to the wrong port. The default port for the Apache Cassandra native protocol is 9042 but it looks you are trying to use 7000.

https://docs.datastax.com/en/cassandra/2.1/cassandra/security/secureFireWall_r.html

Try connecting using cqlsh. Look at the native_transport_port setting in the cassandra.yaml file (9042 by default).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM