public function finish($status = 0, $zombie = false)
    {
        if ($this->state === Generic::STATE_FINISHED) {
            return;
        }

        if (!$zombie) {
            $this->state = Generic::STATE_FINISHED;
        }

        if (!($r = $this->running)) {
            $this->onWakeup();
        }

        while (($cb = array_shift($this->shutdownFuncs)) !== null) {
            try {
                $cb($this);
            } catch (\Exception $e) {
                Daemon::uncaughtExceptionHandler($e);
                // @TODO: break?
            }
        }

        if (!$r) {
            $this->onSleep();
        }

        $this->event('finish');
        $this->onFinish();
        $this->cleanupEventHandlers();

        if (Daemon::$compatMode) {
            return;
        }

        ++Daemon::$process->counterGC;

        if (Daemon::$compatMode) {
            return;
        }

        if (!Daemon::$obInStack) { // preventing recursion
            ob_flush();
        }

        if ($status !== -1) {
            $appStatus = 0;
            $this->postFinishHandler(function () use ($appStatus, $status) {
                $this->upstream->endRequest($this, $appStatus, $status);
                $this->free();
            });
        } else {
            $this->free();
        }
    }