A machine for making liquid or semi-liquid products, comprising: - a first processing container for processing a basic liquid or semi-liquid product and defining a processing chamber; - a cooling cylinder mounted inside the first container; - a first heat exchanger mounted inside the cooling cylinder; - a rotary stirrer mounted inside the chamber - that is, inside the first processing container - and outside the cooling cylinder; - a second processing container; - a connecting duct between the first container and the second container; - a dispensing device associated with the first processing container and configured, in a dispensing configuration, to deliver the liquid or semi-liquid product to the outside or, in an inhibiting configuration, to prevent the liquid or semi-liquid product from being dispensed; - a shutoff valve configured, in a closed configuration, to close the connecting duct between the first container and the second container or, in an open configuration, to open the connecting duct between the first container and the second container; - a control unit operatively connected to the dispensing device to detect the dispensing or inhibiting configuration thereof, and to the shutoff valve in order to drive it between the closed configuration and the open configuration, the control unit being configured to drive the shutoff valve in such a way as to set it to the closed configuration if the dispensing device is in the dispensing configuration, wherein the shutoff valve is defined by a further duct provided with an internal longitudinal through cavity, the further duct being movable vertically between a closed position where the connecting duct is closed and an open position where the connecting duct is open, the machine further comprising a gasket fitted to the further duct and provided with a through cavity in fluid connection with the internal cavity of the further duct, the gasket being sized to come into abutment with a bottom of the second container when the further duct is in the closed position and to prevent the passage of the liquid or semi-liquid product from the second container to the first container. - a first processing container for processing a basic liquid or semi-liquid product and defining a processing chamber; - a cooling cylinder mounted inside the first container; - a first heat exchanger mounted inside the cooling cylinder; - a rotary stirrer mounted inside the chamber - that is, inside the first processing container - and outside the cooling cylinder; - a second processing container; - a connecting duct between the first container and the second container; - a dispensing device associated with the first processing container and configured, in a dispensing configuration, to deliver the liquid or semi-liquid product to the outside or, in an inhibiting configuration, to prevent the liquid or semi-liquid product from being dispensed; - a shutoff valve configured, in a closed configuration, to close the connecting duct between the first container and the second container or, in an open configuration, to open the connecting duct between the first container and the second container; - a control unit operatively connected to the dispensing device to detect the dispensing or inhibiting configuration thereof, and to the shutoff valve in order to drive it between the closed configuration and the open configuration, the control unit being configured to drive the shutoff valve in such a way as to set it to the closed configuration if the dispensing device is in the dispensing configuration, wherein the shutoff valve is defined by a further duct provided with an internal longitudinal through cavity, the further duct being movable vertically between a closed position where the connecting duct is closed and an open position where the connecting duct is open, the machine further comprising a gasket fitted to the further duct and provided with a through cavity in fluid connection with the internal cavity of the further duct, the gasket being sized to come into abutment with a bottom of the second container when the further duct is in the closed position and to prevent the passage of the liquid or semi-liquid product from the second container to the first container.