Brain wake up vs find out something illogical in your dream, what is coming first?

For example today in my dream i just see a fish fly around, I realize something is wrong but don't know what it's (I even can't remember fish live under water and just know something is not right). Then I try think hard what made a fish can fly and I suddenly wake up.

So my question : Because I find out a illogical -> my brain working harder to solve it-> I wake up or i just nearly wake up-> my brain go active -> find out a illogical.