It may be inevitable. In video encoding, there are full frames, carrying all data from the current video frame, and differential frames that only carry the difference between a full frame and the current video frame. With h.264 encoding, these difference frames don't necessarily depend on the last full frame, they may also depend on the next full frame. They are looking into the future, because the future may be more similar to the present than the past, thus requiring less data to encode the difference, which improves video quality.
If you terminate the stream before this next full frame, the actual encoding and transmission has to stop before this differential future-referencing frame, because this differential frame cannot be visualized - its reference frame will never exist.