avoid race conditions when stablishing db connection