Skip to content

Commit

Permalink
MDL-53516 search: Workaround for curl 7.35.0 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmerrill committed Mar 30, 2016
1 parent 79efd94 commit 7a4a0bc
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions search/engine/solr/classes/engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class engine extends \core_search\engine {
*/
protected $client = null;

/**
* @var bool True if we should reuse SolrClients, false if not.
*/
protected $cacheclient = true;

/**
* @var \curl Direct curl object.
*/
Expand All @@ -75,6 +80,21 @@ class engine extends \core_search\engine {
*/
protected $highlightfields = array('title', 'content', 'description1', 'description2');

/**
* Initialises the search engine configuration.
*
* @return void
*/
public function __construct() {
parent::__construct();

$curlversion = curl_version();
if (isset($curlversion['version']) && stripos($curlversion['version'], '7.35.') === 0) {
// There is a flaw with curl 7.35.0 that causes problems with client reuse.
$this->cacheclient = false;
}
}

/**
* Prepares a Solr query, applies filters and executes it returning its results.
*
Expand All @@ -90,7 +110,7 @@ public function execute_query($filters, $usercontexts) {
$data = clone $filters;

// If there is any problem we trigger the exception as soon as possible.
$this->client = $this->get_search_client();
$client = $this->get_search_client();

$serverstatus = $this->is_server_ready();
if ($serverstatus !== true) {
Expand Down Expand Up @@ -160,9 +180,9 @@ public function execute_query($filters, $usercontexts) {
$query->setGroup(true);
$query->setGroupLimit(3);
$query->addGroupField('solr_filegroupingid');
return $this->grouped_files_query_response($this->client->query($query));
return $this->grouped_files_query_response($client->query($query));
} else {
return $this->query_response($this->client->query($query));
return $this->query_response($client->query($query));
}
} catch (\SolrClientException $ex) {
debugging('Error executing the provided query: ' . $ex->getMessage(), DEBUG_DEVELOPER);
Expand Down Expand Up @@ -909,12 +929,12 @@ public function is_server_ready() {
return 'No solr configuration found';
}

if (!$this->client = $this->get_search_client(false)) {
if (!$client = $this->get_search_client(false)) {
return get_string('engineserverstatus', 'search');
}

try {
@$this->client->ping();
@$client->ping();
} catch (\SolrClientException $ex) {
return 'Solr client error: ' . $ex->getMessage();
} catch (\SolrServerException $ex) {
Expand Down Expand Up @@ -944,6 +964,8 @@ public function is_installed() {
/**
* Returns the solr client instance.
*
* We don't reuse SolrClient if we are on libcurl 7.35.0, due to a bug in that version of curl.
*
* @throws \core_search\engine_exception
* @param bool $triggerexception
* @return \SolrClient
Expand All @@ -970,13 +992,17 @@ protected function get_search_client($triggerexception = true) {
'timeout' => !empty($this->config->server_timeout) ? $this->config->server_timeout : '30'
);

$this->client = new \SolrClient($options);
$client = new \SolrClient($options);

if ($this->client === false && $triggerexception) {
if ($client === false && $triggerexception) {
throw new \core_search\engine_exception('engineserverstatus', 'search');
}

return $this->client;
if ($this->cacheclient) {
$this->client = $client;
}

return $client;
}

/**
Expand Down

0 comments on commit 7a4a0bc

Please sign in to comment.