Of course its only a matter of time, because the sun has to burn out eventually.
Other than that, I'd have to say a large asteroid strike(which will become impossible as we set up defences against such astronomical terror). As well, nuclear warfare would greatly decrease the amount of humans on the earth, but never totally destroy them, if you added a noncurable, airborne, fatal biological weapon, then you'd have yourself the end of humanity.
Of course,we could always invent a nanobug that could take out the biological weapon, but then the enemies of the world would make them into destructive beings and have them ripping apart humans 24/7.
But since humanity can generally outlive most of these catastrophes, we will probably live on until the end of time, unless we get extremely unlucky.