Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'key' of undefined #28

Open
dmuth opened this issue Apr 26, 2012 · 13 comments
Open

TypeError: Cannot read property 'key' of undefined #28

dmuth opened this issue Apr 26, 2012 · 13 comments

Comments

@dmuth
Copy link

dmuth commented Apr 26, 2012

Good Evening,

I'm running the latest version of this module, node.js 0.6.11, and Cassandra 1.1.0.

I am able to consistently get this error to happen with the following CQL:

log event: cql -- "CREATE KEYSPACE test_keyspace WITH strategy_class = 'SimpleStrategy' AND strategy_options:replication_factor=1"
log event: info -- "connecting 10.244.207.16:9160(3)"
log event: cql -- "SELECT * FROM 'test1' "
log event: cql -- "CREATE COLUMNFAMILY test1 (id uuid PRIMARY KEY) "
log event: cql -- "UPDATE test1 SET name='Doug', num='123' WHERE id = '1d30f3f2-8435-4ea0-8e33-59c5f5a198b5'"
log event: cql -- "SELECT * FROM test1"

When I issue that SELECT, I get this error:

TypeError: Cannot read property 'key' of undefined
  at [object Object].decode (/data/var/www/doug.cliquetap.zooyan.com/node.js/node_modules/cassandra-client/lib/decoder.js:205:32)
  at new <anonymous> (/data/var/www/doug.cliquetap.zooyan.com/node.js/node_modules/cassandra-client/lib/driver.js:155:22)
  at /data/var/www/doug.cliquetap.zooyan.com/node.js/node_modules/cassandra-client/lib/driver.js:438:23
  at /data/var/www/doug.cliquetap.zooyan.com/node.js/node_modules/cassandra-client/node_modules/thrift/lib/thrift/connection.js:80:11
  at Object.recv_execute_cql_query (/data/var/www/doug.cliquetap.zooyan.com/node.js/node_modules/cassandra-client/lib/gen-nodejs/Cassandra.js:6231:12)
  at /data/var/www/doug.cliquetap.zooyan.com/node.js/node_modules/cassandra-client/node_modules/thrift/lib/thrift/connection.js:83:36
  at Socket.<anonymous> (/data/var/www/doug.cliquetap.zooyan.com/node.js/node_modules/cassandra-client/node_modules/thrift/lib/thrift/transport.js:69:9)
  at Socket.emit (events.js:67:17)
  at TCP.onread (net.js:347:14)

That's a little um, surprising. :-)

I dug into things a little deeper and put some debug code into thrift/lib/thrift/connection.js. I saw that I am in fact fetching the data successfully from Cassandra, but for whatever reason, this.validators is undefined at line 205 in decoder.js.

Is there anything else I can try on my end to get this to work?

Thanks for your time,

-- Doug

@Kami
Copy link
Contributor

Kami commented Apr 27, 2012

Thanks for the bug report.

It looks like a legit bug. Currently our code discovers all the available column families (using describe_keyspace) and builds validators for them when it successfully establish a connection to Cassandra.

This won't work if you create a new column family and as a part of the same session execute a query which operates on this new column family.

I will think about it and try to come up with a more efficient solution which doesn't require consistently using describe_keyspace.

@dmuth
Copy link
Author

dmuth commented Apr 27, 2012

Hi,

Thanks for the clarification. It turns out that reconnecting after creating a column family is a simple workaround!

The big picture, BTW, is that I'm writing unit tests for my code, and what I generally do is set up and teardown a complete environment for each test, which includes entire keyspaces.

Since this is probably an edge case, instead of re-architecting your stuff, may I suggest an alternative? How about logic like this:

  1. If a call to execute() is made that has the string "CREATE COLUMNFAMILY" present, a flag is set.

  2. On subsequent calls to that function in decoder.js, if this.validators is undefined AND the flag from handle null/undefined query parameters with grace #1 is set, a warning is printed with console.error() explaining what you just explained, suggesting that the developer just reconnect, and possibly including the URL to this bug for further reading? :-)

All the best,

-- Doug

@dmuth
Copy link
Author

dmuth commented Apr 27, 2012

Hmm, I may have found something else related to the current issue. Take a look at this debug output:

log event: cql -- {"query":"CREATE COLUMNFAMILY test1 (id uuid PRIMARY KEY, num int) ","parameterized_query":"CREATE COLUMNFAMILY test1 (id uuid PRIMARY KEY, num int) ","args":[]}
log event: info -- "connecting 10.244.207.16:9160(4)"
log event: cql -- {"query":"UPDATE test1 SET name=?, num=? WHERE id = ?","parameterized_query":"UPDATE test1 SET name='Doug', num='123' WHERE id = 'c393ac3c-ddeb-4e70-9bf4-0184ae71db8e'","args":["Doug",123,"c393ac3c-ddeb-4e70-9bf4-0184ae71db8e"]}
{ name: 'InvalidRequestException',
why: 'Unknown identifier name',
message: 'Unknown identifier name',
connectionInfo: { host: '10.244.207.16', port: 9160, keyspace: 'test_keyspace' } }

BUT, this doesn't always happen 100% of the time.

Also, the CREATE COLUMNFAMILY and UPDATE statements work just run when I do them from cqlsh on the command line.

I'm still getting the hang of Cassandra, so again please let me know if I'm doing anything improperly here.

Thanks,

-- Doug

@Kami
Copy link
Contributor

Kami commented Apr 27, 2012

Yeah, reconnecting when creating a column family is definitely one of the options, but it's not the most efficient one :)

I will also wait for @gdusbabek, maybe he has a better solution in mind.

@gdusbabek
Copy link
Contributor

@dmuth your idea about setting a flag to indicate that meta information should be re-collected is a good idea.

As far as the subsequent error, it looks like it is coming from from Cassandra. Are there exceptions in the cassandra log that correspond with the error you see?

@dmuth
Copy link
Author

dmuth commented Apr 27, 2012

Oddly enough, I tried writing a separate test case for the second issue, but was unable to reproduce it. Then I went back to my first test case, and was unable to reproduce it there. Since I'm still learning Cassandra (both client side and server side admin...), I think I can I classify that as a case of PEBKAC on my part. :-)

If you gentlemen would like to keep this bug open or closed, that's up to you. I found a workaround which works for my specific case.

-- Doug

@sebinsua
Copy link

/var/service/node_modules/cassandra-client/node_modules/thrift/lib/thrift/connection.js:90
throw e;
^
TypeError: Cannot read property 'key' of undefined
at [object Object].decode (/var/service/node_modules/cassandra-client/lib/decoder.js:222:32)
at new (/var/service/node_modules/cassandra-client/lib/driver.js:185:22)
at /var/service/node_modules/cassandra-client/lib/driver.js:549:21
at /var/service/node_modules/cassandra-client/node_modules/thrift/lib/thrift/connection.js:80:11
at Object.recv_execute_cql_query (/var/service/node_modules/cassandra-client/lib/gen-nodejs/Cassandra.js:7126:12)
at /var/service/node_modules/cassandra-client/node_modules/thrift/lib/thrift/connection.js:83:37
at Socket. (/var/service/node_modules/cassandra-client/node_modules/thrift/lib/thrift/transport.js:69:9)
at Socket.emit (events.js:67:17)
at TCP.onread (net.js:347:14)

@sebinsua
Copy link

Happened to me, too. : (

@gdusbabek
Copy link
Contributor

@Bedtimes, can you verify that the keyspace and column family exist?

@shroffrushabh
Copy link

Hey Guys, I am running in with the same problem.

TypeError: Cannot read property 'key' of undefined

I have defined the CF and the keyspace. The insert works perfectly, but it's the select which is the problem. So is this bug still open, or it has been fixed and I am making some silly error in my code. I am using node v0.10.5 and Cassandra 1.2.5.

@jirwin
Copy link
Contributor

jirwin commented May 22, 2013

@shroffrushabh This bug is definitely still open. I'm taking another look at it to see if I can come up with a fix.

@shroffrushabh
Copy link

Thank you, I switched to using python flask because of this. Hope you fix it so I can use Node again.

@robert-chiniquy
Copy link
Contributor

Wow, all of Node is riding on this. We really need to fix this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants