We investigate the conditions for the existence of an expanding virial shock in the gas falling within a spherical dark-matter halo . The shock relies on pressure support by the shock-heated gas behind it . When the radiative cooling is efficient compared to the infall rate the post-shock gas becomes unstable ; it collapses inwards and can not support the shock . We find for a monoatomic gas that the shock is stable when the post-shock pressure and density obey \gamma _ { eff } \equiv ( d \ln P / dt ) / ( d \ln \rho / dt ) > 10 / 7 . When expressed in terms of the pre-shock gas properties at radius r it reads \rho r \Lambda ( T ) / u ^ { 3 } < .0126 , where \rho is the gas density , u is the infall velocity and \Lambda ( T ) is the cooling function , with the post-shock temperature T \propto u ^ { 2 } . This result is confirmed by hydrodynamical simulations , using an accurate spheri-symmetric Lagrangian code . When the stability analysis is applied in cosmology , we find that a virial shock does not develop in most haloes that form before z \sim 2 , and it never forms in haloes less massive than a few 10 ^ { 11 } M _ { \odot } . In such haloes , the infalling gas is not heated to the virial temperature until it hits the disc , thus avoiding the cooling-dominated quasi-static contraction phase . The direct collapse of the cold gas into the disc should have nontrivial effects on the star-formation rate and on outflows . The soft X-ray produced by the shock-heated gas in the disc is expected to ionize the dense disc environment , and the subsequent recombination would result in a high flux of L _ { \alpha } emission . This may explain both the puzzling low flux of soft X-ray background and the L _ { \alpha } emitters observed at high redshift .