Such a failure is called unintended intraoperative awareness, and it occurs for about 1 or 2 people for every 1,000 who go through full anesthesia for surgical procedures. But most of the time, it is difficult to detect such a failure because the patients are given muscle relaxers and cannot move their muscles to alert the doctors about their situation.
So, in most of these occurrences, the patient silently bears everything and hears everything without anything being done, simply because nobody knows. But if the patient is able to alert the doctors, or the doctors detect this to have happened, they can do something. The doctors overcome failed anesthesia by giving a higher dose of anesthetics and they will quickly put the patient to sleep. The extra dosage of anesthetic medicines will enable them to go back to sleep quickly and will be able to proceed normally.