I'm getting the following error when running cron with Link Checker enabled on several 9.2.7 sites:

TypeError: Argument 1 passed to Drupal\linkchecker\Plugin\LinkStatusHandlerBase::handle() must implement interface Drupal\linkchecker\LinkCheckerLinkInterface, null given, called in /Users/dicksb/Sites/MAMP/moweb/docroot/modules/contrib/linkchecker/src/Plugin/QueueWorker/LinkStatusHandle.php on line 79 in /Users/dicksb/Sites/MAMP/moweb/docroot/modules/contrib/linkchecker/src/Plugin/LinkStatusHandlerBase.php on line 107 #0 /Users/dicksb/Sites/MAMP/moweb/docroot/modules/contrib/linkchecker/src/Plugin/QueueWorker/LinkStatusHandle.php(79): Drupal\linkchecker\Plugin\LinkStatusHandlerBase->handle(NULL, Object(GuzzleHttp\Psr7\Response))
#1 /Users/dicksb/Sites/MAMP/moweb/docroot/core/lib/Drupal/Core/Cron.php(182): Drupal\linkchecker\Plugin\QueueWorker\LinkStatusHandle->processItem(Array)
#2 /Users/dicksb/Sites/MAMP/moweb/docroot/core/lib/Drupal/Core/Cron.php(147): Drupal\Core\Cron->processQueues()
#3 /Users/dicksb/Sites/MAMP/moweb/docroot/core/lib/Drupal/Core/ProxyClass/Cron.php(75): Drupal\Core\Cron->run()
#4 /Users/dicksb/Sites/MAMP/moweb/vendor/drush/drush/src/Drupal/Commands/core/DrupalCommands.php(76): Drupal\Core\ProxyClass\Cron->run()
#5 [internal function]: Drush\Drupal\Commands\core\DrupalCommands->cron(Array)
#6 /Users/dicksb/Sites/MAMP/moweb/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#7 /Users/dicksb/Sites/MAMP/moweb/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#8 /Users/dicksb/Sites/MAMP/moweb/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#9 /Users/dicksb/Sites/MAMP/moweb/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(313): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 /Users/dicksb/Sites/MAMP/moweb/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /Users/dicksb/Sites/MAMP/moweb/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /Users/dicksb/Sites/MAMP/moweb/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /Users/dicksb/Sites/MAMP/moweb/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /Users/dicksb/Sites/MAMP/moweb/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /Users/dicksb/Sites/MAMP/moweb/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /Users/dicksb/Sites/MAMP/moweb/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#17 /Users/dicksb/Sites/MAMP/moweb/vendor/drush/drush/drush(4): require('/Users/dicksb/S...')
#18 {main}
TypeError: Argument 1 passed to Drupal\linkchecker\Plugin\LinkStatusHandlerBase::handle() must implement interface Drupal\linkchecker\LinkCheckerLinkInterface, null given, called in /Users/dicksb/Sites/MAMP/moweb/docroot/modules/contrib/linkchecker/src/Plugin/QueueWorker/LinkStatusHandle.php on line 79 in Drupal\linkchecker\Plugin\LinkStatusHandlerBase->handle() (line 107 of /Users/dicksb/Sites/MAMP/moweb/docroot/modules/contrib/linkchecker/src/Plugin/LinkStatusHandlerBase.php).
 [warning] Drush command terminated abnormally.

I cannot entirely reproduce this. A fresh install using the same core and the same custom install profile seems able to run cron just fine with Link Checker enabled, while (so far) about a half-dozen existing sites (also on the same core) started experiencing this error when Link Checker was enabled.

Uninstalling Link Checker stops the error. Reinstalling it causes the error to return, even if I don't configure any fields to be checked.

Error occurs both on Acquia Cloud and on my local MAMP environment.

Problem occurs with both 1.0-beta and 1.x-dev.

On a fresh install, I cannot reproduce the error even if I enable all the modules that are enabled on the sites where the error occurs.

I'm still trying to isolate this, but I'm hoping someone else may have an idea.

Command icon 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

wrd-oaitsd created an issue. See original summary.

wrd-oaitsd’s picture

Issue summary: View changes

eiriksm made their first commit to this issue’s fork.

eiriksm’s picture

Weird how you would get in that situation, but can you try the patch from the merge request?

wrd-oaitsd’s picture

Thanks for the quick response! I believe that's solved the problem -- I've successfully run cron on two of the affected sites. I'm working my way through about 50 sites, some of which are throwing a separate, unrelated error that takes some time to correct, so it may be a couple of days before I'm certain about the rest. I'll post again when I can confirm.

wrd-oaitsd’s picture

Yes, I have not encountered this error on any of about 50 sites since applying the patch. Thanks!

eiriksm’s picture

Issue tags: +Needs tests

Great! Let's add some tests here too before we commit.

Thanks for testing and verifying! 💪

joelpittet’s picture

Status: Active » Needs work

Ran into this too. Setting to needs work for the tests.

rex.barkdoll’s picture

Just wanted to comment that this fix worked for me. Running LinkChecker on a D8 site (which will be migrated soon), but I was getting the same error that let me to this and adding the patch/merge request fixed the issue.

Thanks :)

szeberli’s picture

I had the same problem. I have now created a small patch for this.

eiriksm’s picture

To those with the same problem: can we get some steps to reproduce this in here somehow? 🤓

ryan-l-robinson’s picture

Also encountered this today, also as an update to an existing site. This error occurred on cron. If I tried to uninstall linkchecker, I could run cron from drush in the terminal but the entire site would crash with a different error. So obviously we went back to having the error on cron that doesn't affect visitors, at all as far as we can tell.

Drupal core 9.4.8.

PHP 8.0.26.

eiriksm’s picture

Could you test the patch and see if that fixes it for you?

ryan-l-robinson’s picture

I think the answer is yes, but it wasn't as clear as I'd hoped. That error went away on the cron run with the patch applied.

Instead I got another one, which led me to https://www.drupal.org/project/linkchecker/issues/3247797 and followed the last comment there to disable the option to update redirected links.

No posted errors now running cron in the browser or via drush, at least in these first few manual tests. We'll see if it holds up over a few days.

I do still get a site-breaking error if I try to uninstall linkchecker, but hopefully I will never have to do that.

eiriksm’s picture

I have a theory on why this happens. Could it be (to those of you who are experiencing this) that you have gone and deleted some link checker links. Like edit the "check" itself and deleted it?

aitala’s picture

Hi,

Patch seems to work...

No idea why the error was occurring - Is a new Drupal 9 site...

Eric

timfletcher’s picture

I tried Patch #11 after finding issue 3389739 on the 2.x D10 version. The patch suppresses the error but still WSODs the page. Is it possible the cause of the error isn't the cause of the WSOD?

kaszarobert’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.96 KB

I updated the patch with proper array index checking, method argument type checking and catching Throwable to not produce WSOD if Exception or Error is thrown.

promes’s picture

patch #19 works for me.

alt36’s picture

I have a site which is currently throwing this error every time cron runs, and have been trying to figure out reproducible steps without success. However, I am reasonably confident about the following.

I have linkchecker configured to update redirected links after three checks (error.action_status_code_301 = 3)

I have two nodes which contain the same link (identical urlhash value in linkchecker_link table, lid=1643 and 1720, different entity_id__target_id values). The link returns 301 and both rows in linkchecker_link have fail_count=2. The queue table has a couple of hundred rows with name=linkchecker_status_handle. I've made a clone of my Drupal installation to debug and have manually executed "truncate queue".

I run "drush cron". Manually watching the queue table I see many linkchecker_status_handle being created. The "TypeError .. null given" error is then thrown. The queue entry with the smallest item_id has data containing "s:5:"links";a:2:{i:1643;s:4:"1643";i:1720;s:4:"1720";}", i.e it will deserialize to links with lid 1643 and 1720. However, linkchecker_link no longer has the row with lid=1643 but the row for lid=1720 is still present. This presumably is what leads to the error: LinkStatusHandle::processItem() loads a null $link which gets passed unchecked to $hanlder->handle()

joe huggans’s picture

Tested patch #19 and seems to be working

vladimiraus’s picture

Status: Needs review » Reviewed & tested by the community

Thank you for contributing and testing.
RTBC

vladimiraus’s picture

Added changes from patch #19 to MR.

vladimiraus’s picture

Great work everyone.
I no longer have permissions to merge. 🤷‍♂️
Waiting for someone with permissions.

  • vladimiraus committed d0e562cf on 2.0.x authored by eiriksm
    Issue #3247070 by vladimiraus, eiriksm, szeberli, kaszarobert, wrd-...
vladimiraus’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everyone. 🧁
Merged and released.

  • vladimiraus committed 87cc476f on 2.1.x
    Issue #3247070 by vladimiraus, eiriksm, szeberli, kaszarobert, wrd-...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.