Suppose an ideal gas in a piston cylinder has some initial pressure $p_1$, volume $V_1$, and temperature $T_1$. A pin, which holds the piston in place, is suddenly removed, and the gas quickly expands. Once equilibrium is reached, the final pressure of the gas is $p_2$.
I am looking at a textbook solution which claims that the work done during this process is $$W = \int p\,dV = p_2\left(V_2-V_1\right),$$ which implies that the pressure is constant ($p=p_2$) throughout the whole process, as soon as the pin is released. Is this really the case, and are there not irreversibilities in this process that must be considered?