Hang querying empty result #10

Closed
opened 2013-07-23 15:31:09 +01:00 by apb2006 · 6 comments
apb2006 commented 2013-07-23 15:31:09 +01:00 (Migrated from github.com)

package.json: "basex": "~0.6.1"

I create a database, insert a document, and then query for something that is not there.

I am using BaseX 7.6 if that makes any difference.

Maybe you can see it. Here's the debug of what goes back and forth during the whole session:

S1<<
'1374588092554420000\u0000'
S1>>
'admin\u0000'
S1>>
'713de454606e785a0666bd57e6554891\u0000'
S1<<
'\u0000'
S1: authorized
S1>>
'create db gumby\u0000'
S1<<
'\u0000Database 'gumby' created in 5.01 ms.\n\u0000\u0000'
response: { result: '',
info: 'Database 'gumby' created in 5.01 ms.\n',
ok: true }
.S1>>
'\t/people.xml\u0000Gumby\nmanelsePokey\nhorse\u0000'
S1<<
'Path "people.xml" added in 1.88 ms.\n\u0000\u0000'
response: { ok: true, result: 'Path "people.xml" added in 1.88 ms.\n' }
.S1>>
'\u0000//somethingNotThere\u0000'
S1<<
'0\u0000\u0000'
response: { ok: true, result: '0' }
S1>>
'\u00040\u0000'
S1<<
'\u0000\u0000'

And then it hangs, since the callback isn't called.

If, instead, I do a query that does give results back I get the first value prefixed with \000b, which I believe is intended to indicate that the result is an "element".

S1<<
'\u000bGumby\nman\u0000\u000bPokey\nhorse\u0000\u0000\u0000'
response: { ok: true,
result:
[ '\u000bGumby\nman',
'Pokey\nhorse' ] }
{"ok":true,"result":["\u000bGumby\nman","Pokey\nhorse"]}

package.json: "basex": "~0.6.1" I create a database, insert a document, and then query for something that is not there. I am using BaseX 7.6 if that makes any difference. Maybe you can see it. Here's the debug of what goes back and forth during the whole session: S1<< '1374588092554420000\u0000' S1>> 'admin\u0000' S1>> '713de454606e785a0666bd57e6554891\u0000' S1<< '\u0000' S1: authorized S1>> 'create db gumby\u0000' S1<< '\u0000Database \'gumby\' created in 5.01 ms.\n\u0000\u0000' response: { result: '', info: 'Database \'gumby\' created in 5.01 ms.\n', ok: true } .S1>> '\t/people.xml\u0000<people><person>Gumby\nman</person><something>else</something><person>Pokey\nhorse</person></people>\u0000' S1<< 'Path "people.xml" added in 1.88 ms.\n\u0000\u0000' response: { ok: true, result: 'Path "people.xml" added in 1.88 ms.\n' } .S1>> '\u0000//somethingNotThere\u0000' S1<< '0\u0000\u0000' response: { ok: true, result: '0' } S1>> '\u00040\u0000' S1<< '\u0000\u0000' And then it hangs, since the callback isn't called. If, instead, I do a query that does give results back I get the first value prefixed with \000b, which I believe is intended to indicate that the result is an "element". S1<< '\u000b<person>Gumby\nman</person>\u0000\u000b<person>Pokey\nhorse</person>\u0000\u0000\u0000' response: { ok: true, result: [ '\u000b<person>Gumby\nman</person>', '<person>Pokey\nhorse</person>' ] } {"ok":true,"result":["\u000b<person>Gumby\nman</person>","<person>Pokey\nhorse</person>"]}
geralddejong commented 2013-07-23 16:51:31 +01:00 (Migrated from github.com)

It seems I was able to fix it by adjusting the popByte in parser2.js:

this.popByte = function () {
    if (self.data.length) {
        var s = self.data.shift()
        if (s.length == 0) {
            return {data: "\0"}
        } else {
            self.data.unshift(s.substring(1))
            return {data: s[0]}
        }
    }
    else if (self.buffer.length) {
        var s = self.buffer;
        self.buffer = s.substring(1)
        return {data: s[0]};
    }
    else {
        return null;
    }
};

I added the checking if there was anything in the buffer.

It seems I was able to fix it by adjusting the popByte in parser2.js: ``` this.popByte = function () { if (self.data.length) { var s = self.data.shift() if (s.length == 0) { return {data: "\0"} } else { self.data.unshift(s.substring(1)) return {data: s[0]} } } else if (self.buffer.length) { var s = self.buffer; self.buffer = s.substring(1) return {data: s[0]}; } else { return null; } }; ``` I added the checking if there was anything in the buffer.
apb2006 commented 2013-07-23 21:36:12 +01:00 (Migrated from github.com)

That looks good to me. Fixed in v0.6.2 on github and soon npm.
Thanks

That looks good to me. Fixed in v0.6.2 on github and soon npm. Thanks
geralddejong commented 2013-07-23 21:40:42 +01:00 (Migrated from github.com)

Isn't there a danger that this leads to a tight loop while it is waiting for a reply?

Isn't there a danger that this leads to a tight loop while it is waiting for a reply?
apb2006 commented 2013-07-23 21:49:57 +01:00 (Migrated from github.com)

If there is no progress i.e. nothing to parse in the parseResults function then it should exit and only be called again on a data event. At least that is the intent.

If there is no `progress` i.e. nothing to parse in the `parseResults` function then it should exit and only be called again on a data event. At least that is the intent.
geralddejong commented 2013-07-23 22:11:46 +01:00 (Migrated from github.com)

Ah you're right. My returning of null when there's nothing in the buffer causes the while(progress) loop to exit. I guess it can be closed after all.

Ah you're right. My returning of null when there's nothing in the buffer causes the while(progress) loop to exit. I guess it can be closed after all.
apb2006 commented 2013-07-23 22:19:48 +01:00 (Migrated from github.com)

Great. I still think there must be a better approach to the whole async parsing process, but that is for another day.

Great. I still think there must be a better approach to the whole async parsing process, but that is for another day.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
quodatum/basex-node#10
No description provided.