As this answer says, the second version is wrong. It would also be wrong to use the first, because it has problems which you can avoid by recasting part of it.
One problem is not related to the use of "due to". Consider this extract:
By the time the rescuers arrived, which took a long time, they had only eaten 2 peanuts each.
The time the rescuers arrived didn't take a long time --- that's absurd. Perhaps the rescuers' journey took a ling time; perhaps the rescuers departed late. Anyway, the last clause indicates that the pertinent matter is the time the rescuers arrived. So let's recast:
By the time the rescuers arrived, which was late, they had only eaten 2 peanuts each.
Someone who knows more about the story might be able to do better, but this is the best I can do with the information in the OP. The pronoun "they" also needs clarifying. Obviously the parsimonious peanut-eaters are the people rescued, but the sentence makes it refer to the rescuers. So the peanut-eaters need an explicit mention here.
Now let's deal with the "due to" phrase. You could say that the rescuers' late arrival was due to the helicopter problem. The sentence as I recast it mentions the late arrival time but not the late arrival itself. But we don't have to use "due to". we can link clauses in a different way, thus:
By the time the rescuers arrived, which was late because the helicopter was unable to take off, they had only eaten 2 peanuts each.
Using "due to" entails saying something like this:
The rescuers' late arrival was due to the helicopter being unable to take off.
This can't be fitted elegantly into a matrix of the form "By the time X happened, Y had happened". This is the best I can do, working with the added constraint to keep the punchline last:
By the time the rescuers arrived (their late arrival being due to the helicopter being unable to take off), N and N had only eaten 2 peanuts each.