Skip to content
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

Slip lane detection: track visited nodes to avoid infinite loops #3297

Merged
merged 4 commits into from
Sep 3, 2021

Conversation

merkispavel
Copy link
Contributor

Issue

There was an edge with 2 extremely close nodes in the data and distance threshold was never exhausted because edge length was zero. Finally it caused infinite loop and OOM https://github.com/valhalla/valhalla/blob/master/src/mjolnir/linkclassification.cc#L561

The issue is gone now after @gknisely's OSM fix . But it makes sense prevent such looping in the code

This PR adds more robust way not to loop(track all nodes instead of tracking previous edge)

Tests:

  • the pbf around the buggy location is built properly after the fix (loop.osm.pbf.zip)
  • no regressions in turn channel count on maryland.osm.pbf

Tasklist

  • Add tests
  • Add #fixes with the issue number that this PR addresses
  • Update the docs with any new request parameters or changes to behavior described
  • Update the changelog
  • If you made changes to the lua files, update the taginfo too.

Requirements / Relations

Link any requirements here. Other pull requests this PR is based on?

@merkispavel merkispavel changed the title Link classification: track visited nodes to avoid infinite loops Slip lane detection: track visited nodes to avoid infinite loops Aug 30, 2021
if (node_edge.second != prev_edge_idx && !edge.attributes.link &&
IsEdgeDriveableInDirection(node, edge, forward)) {
if (!edge.attributes.link && IsEdgeDriveableInDirection(node, edge, forward) &&
visited_nodes.find(EndNode(node, node_edge.first)) == visited_nodes.end()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the order of check to put hash set lookup in the end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense

Copy link
Contributor

@mandeepsandhu mandeepsandhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a test with 0-length edges in a gurka map?

@merkispavel
Copy link
Contributor Author

Is it possible to add a test with 0-length edges in a gurka map?

@mandeepsandhu reasonable question. I thought about it. My view is it should be possible in theory but it can take much efforts as this bug depends on the order of edges in the data so the test can become useless after code tweaks in the future.
I guess I can give it a try(spend an hour or around and try to reproduce it). I'll let you know if I succeed or not

@mandeepsandhu
Copy link
Contributor

Is it possible to add a test with 0-length edges in a gurka map?

@mandeepsandhu reasonable question. I thought about it. My view is it should be possible in theory but it can take much efforts as this bug depends on the order of edges in the data so the test can become useless after code tweaks in the future.
I guess I can give it a try(spend an hour or around and try to reproduce it). I'll let you know if I succeed or not

Yeah, you dont have to spend too much time trying to recreate it in gurka (especially if the tests is going to be fragile).

BTW, is it possible to test with a OSM extract of the area where @gknisely made the edit? I dont know if cutting a small pbf around that area can help recreate the issue.

@merkispavel
Copy link
Contributor Author

merkispavel commented Aug 30, 2021

@mandeepsandhu I believe valhalla policy is not to use osm extracts and replace them with gurka tests

I dont know if cutting a small pbf around that area can help recreate the issue.

That's exactly how I tested the PR but locally

@mandeepsandhu
Copy link
Contributor

@mandeepsandhu I believe valhalla policy is not to use osm extracts and replace them with gurka tests

True, in that we prefer to add gurka tests for most of our tests. Although I believe exceptions can be made if its difficult or hard-to-reproduce the bug in gurka. This code might change in the future so it'll be good to have some form of test to catch possible regressions.

@merkispavel
Copy link
Contributor Author

Is it possible to add a test with 0-length edges in a gurka map?

@mandeepsandhu reasonable question. I thought about it. My view is it should be possible in theory but it can take much efforts as this bug depends on the order of edges in the data so the test can become useless after code tweaks in the future.
I guess I can give it a try(spend an hour or around and try to reproduce it). I'll let you know if I succeed or not

Yeah, you dont have to spend too much time trying to recreate it in gurka (especially if the tests is going to be fragile).

BTW, is it possible to test with a OSM extract of the area where @gknisely made the edit? I dont know if cutting a small pbf around that area can help recreate the issue.

@mandeepsandhu There's some dark magic happened with this extract. @gknisely and I, we tried to reproduce it with a gurka test but without success. Going to merge it as it is. Local testing should be enough to be safe to merge it(though would be better with gurka 😢 )

note: here's an extract how to assign the same coordinates for two nodes, maybe it'll be helpful in the future

  itr = layout.find("D");
  EXPECT_NE(itr, layout.end());
  midgard::PointLL ll = itr->second;

  itr = layout.find("C");
  EXPECT_NE(itr, layout.end());
  itr->second = ll;

@merkispavel merkispavel merged commit 49e4a18 into master Sep 3, 2021
@nilsnolde nilsnolde deleted the fix-slip-lane-infinite-loop branch February 24, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants