node-tds icon indicating copy to clipboard operation
node-tds copied to clipboard

_handleTokenStream in tds-client.js

Open shawnb457 opened this issue 14 years ago • 32 comments

TypeError: Object #<TdsClient> has no method '_handleTokenStream' at TdsClient. (C:\Program Files\nodejs\node_modules\tds\lib\tds-c lient.js:167:19)

shawnb457 avatar Jan 11 '12 18:01 shawnb457

This is caused by token streams spanning packets. I will fix this shortly.

cretz avatar Jan 11 '12 18:01 cretz

Is there a workaround and/or do you need help in fixing this?

kyberias avatar Jan 12 '12 20:01 kyberias

Actually, I need help replicating it. I was having problems replicating it in my test case. Can you give me the SQL (or JS) that replicates it? I have committed a change that calls the right method, but I want to put in a test case that makes sure your need works.

cretz avatar Jan 12 '12 23:01 cretz

I was able to replicate it with a query to a table that has about 10 columns and returns roughly 20+ rows (SELECT * FROM Table). If I take the exact same query and limit it with TOP 1, it works. Somehow related to the result set size, or number of rows, I guess.

kyberias avatar Jan 13 '12 10:01 kyberias

Here are some observations... I have a table called PlayerAccount with 1313 rows.

"SELECT COUNT(*) FROM PlayerAccount" works "SELECT * FROM PlayerAccount" fails before getting any rows "SELECT Name FROM PlayerAccount" fails after getting roughly 100 rows "SELECT Id FROM PlayerAccount" fails after getting roughly 1000 rows

kyberias avatar Jan 13 '12 15:01 kyberias

Ok, I put in a test case for this issue the other day and it was breaking. Basically, it can't handle multi-packet responses properly (test case here). Basically it fails after ~80 results. I will work on whatever it is causing the problem when spanning packets. I will always accept help too if the code isn't too ugly.

cretz avatar Jan 13 '12 16:01 cretz

I am facing the same issue..!!! The output rows are 24 with 6 columns... but after 12 rows the program breaks.. Need help..

nambad avatar Jan 18 '12 10:01 nambad

I have a similar symptom as @nambad . The result set is 35 rows with 6 columns. The break occurs after receiving row #30.

Checking token type:  209
Retrieved token type:  209
Need 103, length 63
Stream incomplete, rolling back
Received 603 bytes at state 4 <Buffer 74 00 20 00 70 00 65 00 72 00 20 00 41 00 63 00 74 00 69 00 76 00 65 00 20 00 53 00 65 00 73 00 73 00 69 00 6f 00 6e 00 0e 00 64 00 65 00 63 00 69 00 6d ...>

/FOO/console/node_modules/tds/lib/tds-client.js:167
      return this._handleTokenStream();

TypeError: Object #<TdsClient> has no method '_handleTokenStream'

jonbuffington avatar Jan 18 '12 15:01 jonbuffington

I apologize. The method name change is fixed in master, but I am still having problems with streams that span packets. I am working on it...

cretz avatar Jan 18 '12 17:01 cretz

@cretz Thanks. I npm linked to master and the execute succeeds. The only side-effect is the console message: Need 103, length 63

I am new to CoffeeScript but if you point me to the general area, I can lend another set of eyes.

jonbuffington avatar Jan 18 '12 17:01 jonbuffington

This means I went past my expected buffer. Somewhere, I tried to read from my BufferStream past the available length. The console.log definitely shouldn't be enabled by default; I'm sorry about that.

cretz avatar Jan 18 '12 20:01 cretz

@cretz No apologies needed. I will step through the debugger and identify where the issue may be located.

jonbuffington avatar Jan 18 '12 20:01 jonbuffington

We also just came across this issue wondering if anybody has had any luck with a fix/workaround

zachaller avatar Jan 24 '12 19:01 zachaller

The missing method issue is fixed in master, but I am still struggling on fixing the issue where data passes a normal packet's size (see the broken test case in master). Hopefully it wont take too much longer to find the issue.

cretz avatar Jan 24 '12 21:01 cretz

Yea i have been going through it kind of also got the test case fixed and its throwing unrecognized packet type of 60 and going over the buffer just like you mentioned but i am unfamiliar with both tds and your code base so its going super slow hopefully you get it fixed before i can figure anything out, if i even can :) more eyes never hurt though.

zachaller avatar Jan 24 '12 21:01 zachaller

Same problem here ;) Thanks for this module

KillWil avatar Feb 02 '12 09:02 KillWil

I'm experiencing the same thing whenever the returned dataset is more than a handful of records.

noregrets avatar Mar 05 '12 15:03 noregrets

I have committed a fix in master which I think resolves this issue. Once I have other fixes in place, I will release a new version on npm. If anyone wants to test with their specific situation to see if their issue is resolved, I'd appreciate it.

cretz avatar Mar 07 '12 00:03 cretz

Appears to have fixed the issue I was experiencing. Thank you!

noregrets avatar Mar 07 '12 15:03 noregrets

@cretz

I'm running tds from master, and I think I'm experiencing the issue related to large queries. Queries with small result sets return just fine, but larger result sets do not. I'm not receiving an error message from the TDS library at all, so I'm not really sure where things are breaking.

Regardless, thanks for working on this library! It's nice to be able to use node against a more "enterprise" database.

rickbergfalk avatar Mar 16 '12 19:03 rickbergfalk

Can you provide me an example preferably with temp tables? I already have this test.

cretz avatar Mar 16 '12 19:03 cretz

Ok, I have added another test case which does show an error still existing with multiple varchar rows (see commit above). I am still investigating...

cretz avatar Mar 20 '12 23:03 cretz

I was having a problem similar to what @redidas comments but I realized that the problem was because my query was returning some NULL values in varchar fields, so when I removed the fields containing NULL values from the query or replaced NULL values with ISNULL(field, '') it worked again with no problems.

Also, I don't know if I should ask for support in this place but I couldn't find somewhere else so here it is: I've been trying to insert NULL values in some fields, but when I do something like this:

stmt.execute({ foo: "foo", bar: null });

the library throws an error apparently because I didn't send a value for "bar" field. So my question is: How can I insert a NULL value?

Thanks for your support and by the way, thanks for this library.

cakedev avatar Mar 24 '12 16:03 cakedev

Getting the same issue here. I must limit my query to top 40 otherwise, i get the handleTokenStream error with the npm release. With the latest release, i don't get this error. Instead, the query hang after a certain number of rows. If i try to do another execute, i get an error that a statement is already executing.

philcar avatar Mar 29 '12 02:03 philcar

Yeah, I have the broken test case in there, just haven't gotten around to digging. It can be very difficult (not made easier by my spaghetti code in tds-client.coffee)

cretz avatar Mar 29 '12 21:03 cretz

I'm running master, and I get all data. However, when large amounts of data is requested, the done event of the statement is not firing. If i limit the query with TOP 10 or something like that, the event fires.

ldv2001 avatar Apr 19 '12 12:04 ldv2001

Has this been fixed by anyone? I am getting this error right now...

0dc2 avatar Sep 06 '13 01:09 0dc2

I'm getting this error too.

Need 1455, length 1440

TypeError: Object #<TdsClient> has no method '_handleTokenStream'
  at TdsClient.exports.TdsClient.TdsClient._socketData (node_modules/tds/lib/tds-client.js:167:19)
  at Socket.<anonymous> (node_modules/tds/lib/tds-client.js:2:59)
  at Socket.EventEmitter.emit (events.js:95:17)
  at Socket.<anonymous> (_stream_readable.js:746:14)
  at Socket.EventEmitter.emit (events.js:92:17)
  at emitReadable_ (_stream_readable.js:408:10)
  at emitReadable (_stream_readable.js:404:5)
  at readableAddChunk (_stream_readable.js:165:9)
  at Socket.Readable.push (_stream_readable.js:127:10)
  at TCP.onread (net.js:526:21)

vjpr avatar Oct 16 '13 15:10 vjpr

Got the same issue ... any fixes for this?

Yannici avatar Sep 29 '14 10:09 Yannici

I fixed this problem. Go to tds-client.js file and find "_handeTokenStream" and replace this method with "_handleToken" ... I think its just a typo by the developer ;)

Yannici avatar Sep 29 '14 10:09 Yannici