Online Software Tournament Test Case

I am working on online poker software and there is 1 issue we faced when testing with tournaments.
Let me explain the case
There were 6 players in the hand
p1 (SB) 2820 chips
p2 (BB) 100 chips
p3 15990 chips
p4 10445 chips
p5 215 chips
p6 (D) 25325 chips
Blinds were 500/1000, Ante 100
So firstly I took the Ante from players and since all players have sufficient money to post the ante there was no side pot created when I evaluated the stacks.
Pots Info after ante posted 600(p1, p2, p3, p4, p5, p6)
After this Blinds were posted and since p1(SB) has sufficient amount for small blind he post the small blind but p2 was all-in blinds were not posted by him.
In preflop round following actions were taken by players:
p1 posts SB stacks[p1] = 500
p2 All-in stacks[p2] = 0
p3 Fold stacks[p3] = 0
p4 Fold stacks[p4] = 0
p5 Fold stacks[p5] = 0
p6 Raise(25225) and goes All-in stacks[p6] = 25225
p1 Folds
p2 was already all-in turn didn't went to him

Now what went wrong was after this when I evaluated the stacks again since there was no side-pot created earlier what happened was that p6 raised amount went to main-pot along with 500 from p1 and now the pots information was like
26325(p2, p6)
And in this case, p2 has a better hand than p6 so he took 26325 pot with him
Now I know this is not how it was supposed to run I think the right way(correct me If I am wrong) for this hand to be evaluated was like this
600(p2, p6) 25725(p6)
So p6 gets the side pot 25725 and p2 gets 600 pot
But since p2 has exactly the same amount as was required by ante no side pot was created when ante was evaluated, and since no other player called side pot was not created later also
My question is how should I check for this case should I treat as a special case?
Can this happen with any position if he has only that much amount to post ante only? (I think it will)
Please note that In cases when players have less hand money than ante side pot do get created in this scenario It was exactly the same amount as ante
1 way I was thinking to fix this bug was to check if (there is 1 pot) AND (1 or more players are all-in) after posting the ante and then creating a side pot having only those players who are not all-in but I am not sure maybe I will miss some other case? Please provide feedback Thanks