Remove every line that include and follows the second occurrence of a given pattern
This should be pretty speedy:

awk '/bar/ {n++} n==2 {exit} {print}' file


To pass the pattern from the shell:

awk -v p="$pattern" '$0 ~ p {n++} n==2 {exit} {print}' file