Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1887475 possible fix OOM issue #421

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified libsnowflakeclient/deps-build/linux/curl/lib/libcurl.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified libsnowflakeclient/lib/linux/libsnowflakeclient.a
Binary file not shown.
Binary file modified libsnowflakeclient/lib/win64/vs16/snowflakeclient.lib
Binary file not shown.
Binary file modified libsnowflakeclient/lib/win64/vs17/snowflakeclient.lib
Binary file not shown.
4 changes: 4 additions & 0 deletions snowflake_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ static int pdo_snowflake_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
cols[i].maxlen = (size_t) F[i].byte_size;
break;
}
if (cols[i].name)
{
zend_string_release(cols[i].name);
}
cols[i].name = zend_string_init(
F[i].name, strlen(F[i].name), 0);
#if (PHP_VERSION_ID < 80100)
Expand Down
94 changes: 94 additions & 0 deletions tests/memory_usage.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
--TEST--
pdo_snowflake - memory usage
--INI--
pdo_snowflake.logdir=sflog
pdo_snowflake.loglevel=DEBUG
pdo_snowflake.cacert=libsnowflakeclient/cacert.pem
--FILE--
<?php
include __DIR__ . "/common.php";

$dbh = new PDO($dsn, $user, $password);
$mem_usage_org = 0;
for ($i = 0; $i < 5; $i++) {
#collect original memory usage with second one since there is memory usage for one time initialize
# in the first one.
if ($i == 1)
{
$mem_usage_org = memory_get_usage();
}
try {
echo 'Memory usage before connection: ' . memory_get_usage() . "\n";
$pdo = new PDO($dsn, $user, $password);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$query = 'SELECT * FROM SNOWFLAKE_SAMPLE_DATA.TPCH_SF1000.ORDERS LIMIT 10000';

echo 'Memory usage before query execution: ' . memory_get_usage() . "\n";
$stmt = $pdo->prepare($query);
$stmt->execute();
echo 'Memory usage before fetching: ' . memory_get_usage() . "\n";
$records = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo 'Memory usage after fetching: ' . memory_get_usage() . "\n";
} catch (PDOException $e) {
echo "Unexpected failure: " . $e->getMessage() . "\n";
} finally {
if ($records) {
$records = null;
echo 'Memory usage after fetching data cleaning: ' . memory_get_usage() . "\n";
}
if ($stmt) {
$stmt = null;
echo 'Memory usage after stmt cleaning: ' . memory_get_usage() . "\n";
}
if ($pdo) {
$pdo = null;
echo 'Memory usage after pdo cleaning: ' . memory_get_usage() . "\n";
}
}
if (($mem_usage_org > 0) && (memory_get_usage() > $mem_usage_org))
{
echo 'Possible memory leak: original: ' . $mem_usage_org. 'current: ' . memory_get_usage() . "\n";
}
}
$dbh = null;
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
Memory usage before connection: %s
Memory usage before query execution: %s
Memory usage before fetching: %s
Memory usage after fetching: %s
Memory usage after fetching data cleaning: %s
Memory usage after stmt cleaning: %s
Memory usage after pdo cleaning: %s
Memory usage before connection: %s
Memory usage before query execution: %s
Memory usage before fetching: %s
Memory usage after fetching: %s
Memory usage after fetching data cleaning: %s
Memory usage after stmt cleaning: %s
Memory usage after pdo cleaning: %s
Memory usage before connection: %s
Memory usage before query execution: %s
Memory usage before fetching: %s
Memory usage after fetching: %s
Memory usage after fetching data cleaning: %s
Memory usage after stmt cleaning: %s
Memory usage after pdo cleaning: %s
Memory usage before connection: %s
Memory usage before query execution: %s
Memory usage before fetching: %s
Memory usage after fetching: %s
Memory usage after fetching data cleaning: %s
Memory usage after stmt cleaning: %s
Memory usage after pdo cleaning: %s
Memory usage before connection: %s
Memory usage before query execution: %s
Memory usage before fetching: %s
Memory usage after fetching: %s
Memory usage after fetching data cleaning: %s
Memory usage after stmt cleaning: %s
Memory usage after pdo cleaning: %s
===DONE===