Setup
- Solr version: 8.11.3
- Drupal Core version: 11.3.5
- Search API version: 1.40.0
- Search API Solr version: 4.3.10
- Configured Solr Connector: standard
Issue
SolrConnectorPluginBase::connect() creates a new Solarium\Client each time the connector is reinstantiated, but the old client is never freed. In long-lived PHP processes such as a full Behat test suite run, Solarium\Client instances accumulate indefinitely in memory and are never garbage-collected.
Solarium\Plugin\CustomizeRequest registers itself as a listener on the injected event dispatcher when first used, creating a circular reference: event dispatcher → CustomizeRequest → Solarium\Client → event dispatcher
PHP's reference counting cannot break this cycle, so every discarded client stays in memory for the lifetime of the process. In long-lived processes (Behat, Drush, migrations), this causes unbounded accumulation.
Proposed resolution
Implement __destruct() on SolrConnectorPluginBase to call Client::removePlugin()` on each plugin, which triggers deinitPlugin() and removes the listener, breaking the cycle:
public function __destruct() {
if ($this->solr) {
foreach (array_keys($this->solr->getPlugins()) as $key) {
$this->solr->removePlugin($key);
}
}
}
Issue fork search_api_solr-3584036
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
herved commentedPR: https://github.com/mkalkbrenner/search_api_solr/pull/118
Comment #3
herved commentedFor context, even with 2,226 accumulated
Solarium\Clientinstances across a full behat test suite run, the total memory footprint was ~800 KB. So this is not a significant memory concern in practice, but the dangling listeners are still a correctness issue as they keep stale clients reachable and could cause listeners to fire on discarded connectors.Comment #4
mkalkbrennerCan you open a MR here at drupal.org?
Comment #5
herved commentedOh, is github no longer used? the project page still mentions to use it, under "Patches and Issues Workflow" https://www.drupal.org/project/search_api_solr
Comment #6
mkalkbrenneryes, the tests are now working here. I just removed the statement from the project page. Thanks :-)
Comment #8
herved commentedComment #10
mkalkbrenner