Fly from Canada to US
Most of the time, you pass the CBP check in the Canadian airport. For some flights, you won't be checked at the Canadian airport but after you arrive at US airports. Basically, for those flights, the US Customs is closed before the flight takes off.