-
Notifications
You must be signed in to change notification settings - Fork 15
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
Upgrade asynciterator to v3.x #71
Conversation
@rubensworks The upgrade of our Comunica dependencies introduces unpredictable timeouts in |
This appears to be a very painfull one to debug... Some findings in the meantime:
|
Is there an alternative |
Buffering would be one obvious alternative (which will fix the problem). But I don't think we want that, as we would lose lazy streaming. To clarify, I don't think This is confirmed by checking how many times the |
Does Comunica listen for listener unsubscribes and react immediately? |
No, it does not. But AFAICS comunica should not listen to unsubscribes, as asynciterator should handle those, right? |
And it seems to be covered indeed: |
There's actually a possible race condition: while (this.listenerCount('data') !== 0 && (item = this.read()) !== null)
this.emit('data', item); What is the listener is removed when |
FYI just tried changing it into // Reads the next item
function readNext(resolve, reject) {
if (pendingError)
return reject(pendingError);
if (readable.done)
return resolve({ value: undefined, done: true });
// Try to see if an item is already available
const item = readable.read();
if (item !== null)
return resolve({ value: item, done: false });
// Attach stream listeners
readable.once('data', yieldValue);
readable.once('end', finish);
readable.once('error', finish); but does not help. |
…and a Heisenbug, too. Inserting logging makes it more likely for the error not to occur. |
I'll try to see if I can reproduce it without Comunica and LDflex. |
And even worse, when trying the scenario outside of Jest (to get rid of the whole ceremony Jest inserts around |
That's not good :-( At least we know how to reproduce it in the browser, so that's something: #45 (comment) |
In any case, the whole listener reattachment code has too many moving
pieces; we’re literally switching from flow to non-flow mode hundreds of
times per second. That’s bound to fail. So I will change that regardless,
and maybe that fixes it.
|
Sounds good. One solution might be to create an async variant on |
Implemented So you can |
Interesting finding: with this change, the test "main profile fields" also starts failing sometimes on my end. This seems to indicate that the problem also occurs for queries with just a single triple pattern, while I used to think it occured only on queries with 2+ triple patterns. |
Another finding: For example, if we have a stream that should go from 1->10, we could have something like this: 1,2,3,4,5,6,7, FREEZE |
Yeah, so it's definitely a race condition somewhere. Hence, we should also be careful with some of the assumptions above, in particular:
Is there any possibility of doing a git bisect? |
Should be possible, but unlikely to be useful I think. I'm quite sure the problem is caused by the asynciterator update, which is part of a large refactoring commit. |
Ok, good news and bad news. Good news: I've identified the problem: https://github.com/comunica/comunica/blob/master/packages/actor-query-operation-bgp-single/lib/ActorQueryOperationBgpSingle.ts#L33-L42 Bad news: Removing this block is (currently) not an option, since it breaks other tests. The way forward:
Comunica's current way of handling metadata internally causes these problems, and needs to be refactored. |
Excellent job on finding the problem. That must've been hard! In addition to identifying it, did we also learn something about how to spot such problems more easily in the future? |
Yes, this definitely goes in my top 10 of most frustrating bugs.
Things would have been simplified a lot if we'd have the ability to print the state of our asynciterators. For example:
Output:
Maybe some kind of global flag to enable this on all iterators would also be useful. |
Yes, I do something similar when debugging them myself. I think it would be good to ship a debug build of asynciterator with such logging functionality built in. |
All of the tests seem to pass on my end in the newly released Comunica version (1.17.0). |
5d132dd
to
3c65a34
Compare
No description provided.