Closed benoitvidis closed 7 years ago
Nice catch!
Found a way to reproduce it 100% of the time. Here are the steps:
{or: [{equals: {foo: 'bar'}}, {exists: {field: 'foo'}}]}
{equals: {foo: 'bar'}}
Sample code with the JS SDK:
var Kuzzle = require('kuzzle-sdk');
var kuzzle = new Kuzzle('localhost', function (err, res) {
if (err) {
console.error(err);
process.exit(1);
}
kuzzle.collection('foo', 'bar').subscribe({or: [{equals: {foo: 'bar'}}, {exists: {field: 'foo'}}]}, () => {})
.onDone((err, room1) => {
kuzzle.collection('foo', 'bar').subscribe({equals: {foo: 'bar'}}, () => {})
.onDone((err, room2) => {
room1.unsubscribe();
setTimeout(() => {console.log('...done'); process.exit(0); }, 10000);
});
});
});
The bug lies in the DSL storage.store()
method: when a filter is registered, containing only already existing subfilters, it does not increment the filters count in the testTables
structure (the conditions index).
When then removing a filter, we decrement the filters count. If it reaches 0, that triggers an index removal. If that index is the last one on a given collection, the structure is cleaned up.
After that, if another unsubscribe
occurs, it tries to clean up the testTables
structure... which is now empty.
The problem occurs in quite a specific case: when a new filter
is created which contains only existing conditions
.
In this situation, the test table filter count is not incremented and the filter fidx
index (contains the index of correlated test table entry) is not updated.
Following a client disconnection:
At a first glance, besides the error handling problem, it looks like a wrong argument is passed from the HotelClerk to the DSL, which expects a filter id.