Fix recursive condy perf issue
This is a fix to #317896 (closed) I've added a test with a timeout to reproduce the issue, i think 1 second is enough even on a slow CI to pass the test with the fix.
@ebruneton, should i squash this PR during the merge ?