Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100189 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21271 invoked from network); 11 Aug 2017 21:04:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2017 21:04:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.178 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.128.178 mail-wr0-f178.google.com Received: from [209.85.128.178] ([209.85.128.178:34769] helo=mail-wr0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D8/49-34801-7CB1E895 for ; Fri, 11 Aug 2017 17:04:09 -0400 Received: by mail-wr0-f178.google.com with SMTP id c24so17308881wra.1 for ; Fri, 11 Aug 2017 14:04:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=Ij6o9LvmBWz+6eVSjFq5SiDMWqN18sb2PC6FXcw85C8=; b=TZ6zZuGzqHn6dHIZCfwKfyxlWyef4bGJhQoQBXewvqIQmI6NvyfaaYV4ySF8631fm6 Y8LvqmRlHVyNMmsxC6JBM2jVSQu/szSZ9B1FRUjmbZGhYlElkWB9CoYvvfaD/nC11zqA 2PfvIuQA1Fw+d6ciwSJejIkbqNGtF7rQCBir7uqmRlGvirxNPhVcHG/WVLuHOH4K583I 5XNtzTtEzaPSt4BxKZEoZJM1jQqxScdtOZSFZqj3B40TT0RXgfbpTkgm0tBaGTAtlsZf gPMvwrljkEbwcaVVzmKy793CWQI8J7tq+TaWsrjt6kv5JiBtYYMa3jAYdHYaimyX20ob TJIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=Ij6o9LvmBWz+6eVSjFq5SiDMWqN18sb2PC6FXcw85C8=; b=O1epSKhzXFUJJ9IKKLV8/qUuN7j2wZM7YjntdWC6yLykfJYKQibQp9fe7h6jhM+jUq BXPG8/N5b2GQkONTLlsIVDp3kxcdlDLUNEIzAmV0+P4EdrffD0CkFmGuRSmS7KyLS6Qt Tad6y7ddFoKhVRgkixT9GK0+FKqPbE7tcIL0q3eki6U3TIZKO01KfcztbIJXBfQqsq6+ uCTgYYsp2+uP8p98FyFZEgcCuLvBMmbgn5PEAC9esVvNn/j/BDmaRmWOL84sJfHP4Ms5 quV/Di8AoVNxgCRtOnfz7DUjdvQW5VSf8OfEeE10eYlFlu4MogLb0rA8f5u4YTi75VFs kBeg== X-Gm-Message-State: AHYfb5ik4DViDLDn8w5fAB/Zb73AoLJu7WT0gjHhJFwhS9rqn4UKKTJc IX7vzgAT40f0PGKU X-Received: by 10.223.176.164 with SMTP id i33mr12484414wra.221.1502485443970; Fri, 11 Aug 2017 14:04:03 -0700 (PDT) Received: from ?IPv6:2a00:23c4:4bd2:6e00:f1e1:1468:9e6b:b860? ([2a00:23c4:4bd2:6e00:f1e1:1468:9e6b:b860]) by smtp.googlemail.com with ESMTPSA id 91sm1641843wrg.83.2017.08.11.14.04.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Aug 2017 14:04:02 -0700 (PDT) To: PHP Internals Message-ID: Date: Fri, 11 Aug 2017 22:03:59 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Stop Exceptions capturing object references for trace arguments From: rowan.collins@gmail.com (Rowan Collins) Hi All, This topic has been discussed a couple of times before: - http://marc.info/?t=138118341600002&r=1&w=2 - http://marc.info/?t=142708828500001&r=1&w=2 - http://marc.info/?t=143798102800002&r=1&w=2 I was inspired to revive the topic by this bug report: https://bugs.php.net/bug.php?id=75056&edit=3 Currently, the backtrace of an Exception stores the following: - function: string - line: integer - file: string - class: string - type: string - args: array This is effectively the same as debug_backtrace() with neither DEBUG_BACKTRACE_PROVIDE_OBJECT nor DEBUG_BACKTRACE_IGNORE_ARGS set. The "args" part of this contains full object references to anything that happens to have been a function argument in the stack, and causes two problems: - Serializing an exception can fail, because some of these referenced objects may be non-serializable (e.g. SimpleXMLElement, PDO). - Destructors for these objects do not fire until the Exception is destructed, causing resources to be held open unexpectedly after the stack has been unwound. (The only other place I know of destructors being unreliable in PHP is if there are circular references, in which case the destructor will only fire when the GC detects the cycle.) Both effects are almost entirely unpredictable, because it depends if the object happens to have been a parameter in the current stack, rather than a local variable or $this reference. The simplest solution would be to simply remove this 'args' key from the backtraces, as when DEBUG_BACKTRACE_IGNORE_ARGS is set on debug_backtrace(). This would mean that any normal exception would hold no object references, so would not extend any lifetimes, and would not trigger any serialization errors. Obviously, this has the downside of breaking any code that makes use of this array; if anyone has examples of practical uses for it I would be grateful to see them, and whether a compromise such as storing the class name but not the object would be useful. Regards, -- Rowan Collins [IMSoP]