Im my previous naswer, I included a terms of order $dt$ in the Lagrangian. It makes the variation somewhat awkward. After some thoughts, I find it is rather nature to employ the dissipation function and incorporated as a generalized force Rayleigh Dissipation.
The dissipation function is basically the power dissipated by the friction force. In this case, the mass ejected is taking away a part of the knietic energy from the system in a similar way of dissipation force.
$$
G(v) = \frac{1}{2} \frac{dm}{dt} (\dot{x}-u)^2
$$
The mass changing rate $\dot{m} =\frac{dm}{dt}$ is negative for rocket motion.
The generalized force
$$
Q = \frac{\partial G}{\partial \dot{x}} = \frac{dm}{dt} (\dot{x}-u)
$$
The Euler-Lagrangian equation with generalized force:
$$
\frac{d}{dt} \left\{ \frac{\partial L}{\partial \dot{x}}\right\} -\frac{\partial L}{\partial x} = Q
$$
Appy to the rocket problem with constant gravity:
$$
L = \frac{1}{2} m \dot{x}^2 - mgx
$$
The Equation of motion:
$$
\frac{d}{dt} \left\{ \frac{\partial L}{\partial \dot{x}}\right\} -\frac{\partial L}{\partial x} = \frac{d m\dot{x}}{dt} + mg = Q
$$
$$
m\ddot{x} + \dot{m}\dot{x} + mg = \dot{m} (\dot{x} - u)
$$
Render the correct rocket equation of motion.
$$
m \dot{v} = -\dot{m} u - m g = |\dot{m}| u - m g.
$$
Another example, throw $dm/dt$ mass rate vertically outside a boat, $u=0$:
$$
m \dot{v} = 0 \to v(t) = \text{constant}
$$
The masses casted outside is moving with same $v$, therefore doesn't change the velocity of the remaining boat (neglecting the vertical shift within our 1-d treatment.)