Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97900 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50654 invoked from network); 20 Jan 2017 20:13:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2017 20:13:59 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain lerdorf.com designates 74.125.82.177 as permitted sender) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 74.125.82.177 mail-ot0-f177.google.com Received: from [74.125.82.177] ([74.125.82.177:34059] helo=mail-ot0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F2/D7-00729-48F62885 for ; Fri, 20 Jan 2017 15:13:58 -0500 Received: by mail-ot0-f177.google.com with SMTP id f9so63548417otd.1 for ; Fri, 20 Jan 2017 12:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lerdorf-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=+56LWQO5iUt4/p4+bMBkTAHPd8r6tlB/alR0rkkhDDY=; b=q3+NJ44I/vl6QYIe2zPqwYwPPGKizqP83Cqn1GhnAbSidb9+xWf8DcHXTy7L7rjZTd GIpSBuTtJm3LSUg/rISE+mTyVCQImYXfsyQDI3uc0mMlQPnwjJUsKHSqSihMcGbTqmYS TNqolADsbxEAOjqzvMF3be6LIB1ET5O5nI4TsCcEBSysrl3S4k7eSR/ggt3CR0R2mA6k 5ULEbLXbh6iFkCeyiIigPDCGX8l2jL4jDnJSF35fX7meUxxM3oUy56bcXz9RF+0iqIKx QecsWMtko6T0IjBPR+0wGxAN7KtRZXygNoupViVk+Ve2jd26q4HdsanAZhyas8gGBQ1C R3OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=+56LWQO5iUt4/p4+bMBkTAHPd8r6tlB/alR0rkkhDDY=; b=jG0AjS860Qh31Ijf2PhiCKSNlisS6Y7x6kEiUI3bre54OYlSZP3y7trLYq2Jx1yKl3 F7nrpwPrLqs1jeKuqv8a1XRibZmx58n8u3rj1tq0XlikSDyOw8+/Q+CJn1eMSi5ugdxQ KqkuPRqDBBr/MX5J6q21zgfnzera33n99gjvk9g/PGGkuLCSx6RHBiNPijYf1qh4yg8V QAyZWElMe8WlgJiDv5UqdQDEEd9x1s9luKc07U8iGG1z3gocVt99Z++Kma3L4PdPy7LB g5DJXNkqv4t98boeHP8RjuE9CvZSVo4yL30anK8f6/zzB1XYY34NpE59ahvB4nzWlQ9f LWZg== X-Gm-Message-State: AIkVDXJSktTLssCv4pgYpxN6VC/z2izKKD64eQvjnKkpV0UfVwED0iVDEYpY9agYDuNJoU5u4N8YqVscQ7m6Fg== X-Received: by 10.157.4.141 with SMTP id 13mr8649925otm.243.1484943227450; Fri, 20 Jan 2017 12:13:47 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.121.84 with HTTP; Fri, 20 Jan 2017 12:13:06 -0800 (PST) Date: Fri, 20 Jan 2017 12:13:06 -0800 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=94eb2c095680958ec905468c49e5 Subject: pdo_sqlite fd leak From: rasmus@lerdorf.com (Rasmus Lerdorf) --94eb2c095680958ec905468c49e5 Content-Type: text/plain; charset=UTF-8 I have been chasing a really odd fd leak which I haven't been able to reproduce manually. The code involved is about as simple as you can get: class C { public static function fn($arg) { $pdo = new PDO('sqlite:/var/dbs/file.db'); $query = $pdo->prepare("SELECT * FROM tb WHERE id = ?"); $query->execute([$arg]); $result = $query->fetch(PDO::FETCH_ASSOC); if (!$result) { throw new RuntimeException("not found" ); } return [ "a" => $result['a'], "b" => $result['b'] ]; } } The symptoms are: - It always starts with a max_execution timeout in the *$pdo->prepare()* call - Many hours after this timeout the httpd process runs out of FDs and lsof shows the httpd process with ~1000 fds open on */var/dbs/file.db* The file.db itself is only read from PHP and isn't being updated in the background by anything. mtime is months ago, but this happens sporadically on a single server out of dozens about once every couple of days. These servers are getting hit hard so it takes hundreds of millions of requests to trigger whatever condition is causing this. It feels like it should be something related to timeouts and the *sqlite_handle_closer() *call: https://github.com/php/php-src/blob/PHP-7.0/ext/pdo_sqlite/sqlite_driver.c#L155-L175 but I have been staring at this code and comparing it to the other pdo drivers and I don't see what makes *pdo_sqlite* special here. This is on PHP 7.0.10 but this code hasn't changed significantly in 7.1 and master. Anyone see anything in PDO that could possibly prevent the *sqlite3_close()* call from being executed, especially in edge conditions around an execution timeout? -Rasmus --94eb2c095680958ec905468c49e5--