domvas
December 8, 2020, 5:14pm
1
Hello,
I’ve encounter ‘segmentation fault’ recently when using php sdk.
I’ve isolated the problem and have some script to reproduce it:
<?php
$config = [
'host' => couchbase_host,
'username' => couchbase_username,
'password' => couchbase_password,
'bucket' => couchbase_bucket,
];
// Connection
$connectionString = $config['host'];
$options = new \Couchbase\ClusterOptions();
$options->credentials($config['username'], $config['password']);
$cluster = new \Couchbase\Cluster($connectionString, $options);
$bucket = $cluster->bucket($config['bucket']);
// Build search query
$search_query = new \Couchbase\MatchSearchQuery($text);
$search_query->field($field);
// Define options
$options = new \Couchbase\SearchOptions();
$options->fields(['email']); // This works
// $options->fields([$field]); // This produces segmentation fault when $cluster->searchQuery is called
// Perform search
$cluster->searchQuery('user_email', $search_query, $options);
Could you check this?
Or give me some advises on something wrong in this code snippet.
Thank you
EDIT:
And sometimes when using:
$options->fields(['email']);
I get:
[cb,WARN] (pcbc/search_options L:151) Non-string value detected in fields array
avsej
December 9, 2020, 7:52am
2
avsej
December 9, 2020, 7:55am
3
What version of PHP interpreter and couchbase SDK are you using by the way?
domvas
December 9, 2020, 8:00am
4
Hi,
i’m already on the 3.0.5.
EDIT: But I will try this build.
Regarding php version:
# php -v
PHP 7.3.19-1~deb10u1 (cli) (built: Jul 5 2020 06:46:45) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.19, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.19-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies
with ddtrace v0.48.3, Copyright Datadog, by Datadog
domvas
December 9, 2020, 1:13pm
5
Using the latest snapshot solves the problem… partially.
I mean that the given example can be successfully executed now.
But there’s still something wrong somewhere.
Consider this function:
<?php
function getByEmail(string $email) {
$options = [
'index' => 'user_email',
];
$options = array_merge(['full_result' => false], $options);
$match_query = new \Couchbase\MatchSearchQuery($email);
$match_query->field('email');
// Manage couchbase search options
$search_options = new \Couchbase\SearchOptions();
// Connection
$config = config('database.couchbase.default');
$connectionString = $config['host'];
$c_options = new \Couchbase\ClusterOptions();
$c_options->credentials($config['username'], $config['password']);
$cluster = new \Couchbase\Cluster($connectionString, $c_options);
//Search
$cluster->searchQuery($options['index'], $match_query, $search_options);
}
In my tests, if I call it once, everything’s fine.
If I call it twice, I’ve got a segmentation fault.
And interestingly, if I remove this line (which is useless I know):
$options = array_merge(['full_result' => false], $options);
I end up with:
mmap() failed: [12] Cannot allocate memory
mmap() failed: [12] Cannot allocate memory
PHP Fatal error: Out of memory (allocated 27262976) (tried to allocate 7017285945777942528 bytes) in /var/www/app/tests/Couchbase/SegFaultTest.php on line 257
[2020-12-09 13:12:36] testing.ERROR: Out of memory (allocated 27262976) (tried to allocate 7017285945777942528 bytes) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Out of memory (allocated 27262976) (tried to allocate 7017285945777942528 bytes) at /var/www/app/tests/Couchbase/SegFaultTest.php:257)
[stacktrace]
#0 {main}
"}
domvas
January 4, 2021, 8:58am
7
Hi,
is there any updates on this topic?
It’s a major blocking issue that prevents FTS usage in a programmatic way.
You can find a clear example here: https://github.com/dominique-vassard/couchbase-segfault
avsej
January 20, 2021, 8:27pm
8
@domvas , it should be fixed now. I’ve just released version 3.1.0, and checked your reproduction script. It does not crash anymore.
domvas
January 21, 2021, 9:30am
9
Hello,
I’ve just made some tests and yes it’s working fine.
Thank you!