If a person becomes junub while he is awake or wakes up after becoming junub in his sleep

Fast Invalidators
To Remain Junub until Morning Adhān
If a person becomes junub while he is awake or wakes up after becoming junub in his sleep, and knows that if he sleeps again will not awake before morning adhān to make ghusl, he should not sleep unless makes ghusl. However, if he sleeps and does not make ghusl before morning adhān, his fast is void. Of course, if he thinks he may wake up before morning adhān and wants to make ghusl, his fast is in order even if he does not wake up. If he [wakes up and] sleeps again but does not wake up before morning adhān, he should make qaḍā’ fast of this day.
Source: Hadana adopted from the Istiftaat of the Grand Ayatollah Khamenei