If your graph contains any cycles, this is the expected behavior; A simple search by depth will first be visited by an already visited child, endlessly looping.
A simple way to avoid this is to add each node to the HashSet after checking to see if it is looking for a node, and then refuses to add it to the stack if it has already been verified.
source share