As soon as a master fails, the remaining slaves can elect a new master.
For instance, MongoDB documentation explains how a new master is elected. Depending on the specific requirements, additional complexity can be added, such as the presence of non-voting members.
If the original master is restored, there are two alternatives:
Either it becomes a new master, and the current master becomes a slave,
Or the machine becomes a slave and would have a chance to become a master only through a new election, once the current master fails.
For non-critical systems, there is another possibility. If a master fails, none of the slaves could replace the master, but they continue to serve read-only requests, awaiting the master to be restored. This could be used successfully in a context where the downtime of the master is acceptable. For instance, if an app stores your favorite movies, the write part can eventually go down for a few minutes once per month—as soon as you can still access your data in read-only mode, the downtime of the part where you change your data is acceptable.