When you find out the girl is not interested or you fail to start a conversation, what do you do?

It gets like very awkward and I'm like do I say bye or do I just walk away??? I know now you need to give signals first like making eye contact for example before approaching them but things can still go south.

This also goes for when you fail a shit test for example.