Currently if the following conditions hold true:
1. output_handler is set in php.ini to ob_gzhandler;
2. output compression is not enabled in phpbb
then exit_handler performs a flush() call.
However, the way ob_gzhandler is implemented is it sets content encoding headers, collects buffered output (output buffering is implicitly turned on when output_handler is used), compresses the output and prints compressed output.
The problem is that flush call in phpbb occurs before ob_gzhandler sets the headers, which is the root of the problem and somehow after going through msg_handler the entire page output is printed a second time.
What should happen is conditional determining whether to use ob_flush or flush in exit_handler should look at whether output buffering is active, not at gzip_compress setting, because as explained output buffering may be turned on outside of phpbb.