graphaware / neo4j-reco

Neo4j-based recommendation engine module with real-time and pre-computed recommendations.
374 stars 77 forks source link

Manage race-condition when RandomRecommendations can't find recommendations #7

Closed andretti1977 closed 9 years ago

andretti1977 commented 9 years ago

When a RandomRecommendations engine can't find a random recommendation, an Assertion fails raising an IllegalArgument exception. This is a problem because it is not obvious why the exception happened and because it may happen due to runtime conditions.

This is line 68 in RandomRecommendations:

Node node = selector.selectNode(input.getGraphDatabase());

it may happen that the the selector (a RandomNodeSelector) couldn't find a node so it will return a null node which will not respect the NotNull assertion on SimpleContext.allow method which is called later.

It is easy to replicate the case: just extend the RandomRecommendations engine with a NodeInclusionPolicy that can't be respected (provide as an example a not existing Label).

But as i told before, it may happen at runtime too because it may happen that nodes that the inclusion policy would accept, would have been removed during runtime operations on the graph, so i think that checking if the node is null, should be performed immediately after the selector.selectNode call and it should be ok that the RandomRecommendations could not return recommendations without exceptions.

bachmanm commented 9 years ago

Thanks for catching this, a fix will be released with the next version