Process all messages before throwing EOF errors

Before throwing EOF errors when the connection is closed, make sure all pending messages are processed.