Fix a regression in which a timeout could fire after being cancelled.

Closes #1148.