Improve the timeout calculation of the command scheduler (see #5775)