Revert "Simplify ID allocation so that we don't loop over all IDs"

This reverts commit a2ac633525c69a94ca3e1f91817a4b421f5375e6.

That commit (sadly) works only for one socket, not for multiple
ones.