until the cows come home
Possibly from the fact that cows may be expected to return for milking in the morning; thus, for example, a party that goes on "until the cows come home" is a very long one.
Alternatively, assuming a Scottish origin, from the fact that cows in the highlands are put out on the common grazing until the end of summer, when they will find their way back home to be let in for feeding. Grass on the hill (common) is plentiful, so cows may stay out for months before scarcity of food brings them home in the autumn.
Reportedly, the first attestation is from the [London] Times:
- 1829, The Times,
- If the Duke will but do what he unquestionably can do, and propose a Catholic Bill with securities, he may be Minister, as they say in Scotland "until the cows come home."
Alternative forms 
Prepositional phrase 
- (idiomatic) For a very long period of time.
- You can crank the engine until the cows come home, but it won't start without fuel.
- 1952, Felix Frankfurter, Supreme Court of the United States, Sacher v. United States: Dissent Frankfurter,
- Now I can't stop lawyers from calling me names and saying I am guilty of judicial misconduct and that I am prejudiced, and this, that and the other thing, and you can keep that up until the cows come home; that is all right, and I take no umbrage at it.
- 2001, Barbara Deckert, Sewing 911: Practical and Creative Rescue for Sewing Emergencies, page 58,
- Particularly if you are sewing synthetics, you can press until the cows come home, but facings may not stay put.
- 2003, National Book Council (Australia), Australian Book Review, Issues 248-257, page 27,
- But I could quote from Animal Warmth and Up On All Fours until the cows come home. I could quote until the cows came home about the cows not coming home.