The first thing to do is to verify that there is in fact a problem, and identify what exactly it is (ideally in the usual bug report form: how to reproduce, intended behavior, actual behavior).
From there, the first thing to do is to inform your team and whoever is responsible for managing the product's code quality (project manager, team leader, product owner, scrum master, whatever). The longer you hide the fact that a mistake was made, the higher the risk of bigger problems ensuing.
The next step is to estimate the impact, find a quick fix to mitigate immediate problems, and deploy it. Then fix the mistake properly, and make sure it is tested thoroughly.
Whether and when you inform your users depends on the nature of the problem. Generally, I believe users have a right to know, unless other concerns weigh stronger. A typical example would be if your mistake causes a security vulnerability: disclosing details about it before a proper fix is deployed would be irresponsible, so in such a case, it is better to inform users after the fact.
And then the most important step: evaluating the situation. Ask yourself (and your team): What caused this problem? What could I/we have done to prevent it? What can we do to avoid similar mistakes in the future? What can be done to mitigate the consequences? Find answers to these questions, and implement them. In other words, make sure you learn from your mistakes - both as an individual and as a team.
There is no shame in making a mistake, but making the same mistake over and over and over is pretty embarrassing, and making a mistake and trying to hide it borders on criminal behavior.