This situation is known as "Aging Out". Thankfully, a recent change to the law - the Child Status Protection Act or CSPA - reduced this problem substantially. Unfortunately, the new rules are very complex.
You should discuss the situation with a lawyer. Also, contact USCIS about six months before the birthday and request expedited processing. Finally, you can ask your local Congressperson for assistance.
The general idea of the Child Status Protection Act is that you can subtract the time that INS/USCIS took to process your petition from the child's age. For instance, if you filed an I-130 in the Family 2A category for a minor child of a Green Card Holder, then look at how long it took for the I-130 to be approved. Let's say that USCIS took three years and four months. In that case, your child would be considered to be "under 21" for I-485 purposes until four months after his 24th birthday.
Today, USCIS is actually helping you here; they deliberately delay processing of I-130 applications until shortly before the priority date is current. They do that to reduce their own workload, but a secondary consideration was the benefit to you; it also maximizes the amount of age-out protection you are getting through the CSPA. This is one example for my philosophy that on balance USCIS is not your enemy (they are not your friend, either).




