question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intermittent issue when loading HUD tools: "cannot read property 'data' of null"

See original GitHub issue

Hi All

I faced an intermittent issue when doing the following:

  1. Enable HUD via icon in toolbar
  2. Open configured browser (chrome in my case) by clicking on icon in toolbar

Sometimes it worked as expected and HUD is displayed, other times it would spike my CPU to 100% and chrome would freeze. Subsequent investigation showed literally thousands of errors being set in the chrome DevTools and ZAP console output, like so:

screenshot from 2018-10-04 17-20-06

screenshot from 2018-10-04 17-19-55

Some investigation revealed that basically the “data” of “null” came from the “loadTool” function in utils.js… the tools were not being saved in indexedDB.

Why that is turns out to be really subtle… if you check the serviceworker.js file, we used a “forEach” loop to in turn call importScripts on each default tool:

var toolScripts = [
	<<ZAP_HUD_TOOLS>>
];

// Load Tool Scripts
localforage.setItem("tools", [])
	.then(() => {
		toolScripts.forEach(script => {  // <--------- here
		 	importScripts(script); 
		});
	})

What I think the issue is, is that forEach actually calls an async function for each loop. In other words, every “importScripts” command in that forEach loop was being processed async, so the promise would return before the importScripts were all processed. This and then causes the null errors.

Turning this into plain vanilla for loop like so seems to sort out the issue on my PC, but i’ll test some more and update this issue (which is serving as my braindump) to make sure it’s not a red herring.

var toolScripts = [
	<<ZAP_HUD_TOOLS>>
];

localforage.setItem("tools", [])
	.then(() => {
		for (var toolScriptCounter = 0; toolScriptCounter < toolScripts.length; toolScriptCounter++){
			var script = toolScripts[toolScriptCounter];
			importScripts(script); 
		}
	})

Other solutions (if this is really the root cause) would be to use async/await in conjunction with the forEach loop

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dscroboniacommented, Oct 16, 2018

Hey @dvas0004 just catching up on this thread. Absolutely love all your details and notes! Thank you so much for including all of that, its super helpful.

I am a little confused about what would be async in this for loop: https://github.com/psiinon/zap-hud/blob/master/src/org/zaproxy/zap/extension/hud/files/hud/serviceworker.js#L46

Isn’t forEach synchronous as well as importScripts? forEach:

importScripts:

There are some major hacks/ ugly-ness in startup right now though. Trying to figure out why this bug would occur but not sure yet. I bet you’re right there is some async happening somewhere though…

0reactions
dvas0004commented, Oct 17, 2018

yes absolutely. I had literally just installed it, and it was on my first run of the HUD, no other tabs and browser was launched through ZAP, not “remotely”

On Wed, 17 Oct 2018 at 09:08, David Scrobonia notifications@github.com wrote:

@dvas0004 https://github.com/dvas0004 just to clarify you are running into this issue when running on a single tab right?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/psiinon/zap-hud/issues/200#issuecomment-430501426, or mute the thread https://github.com/notifications/unsubscribe-auth/AFlDbWR5H855lebOhWp4aITb9kDHYQ5Qks5ulslRgaJpZM4XISau .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting intermittent error: "Cannot read property ... - GitHub
We are occasionally getting an error when the page refreshes: "Cannot read property 'RawSearchReslts' of null. ... Steps to reproduce the behavior ...
Read more >
Cognos Analytics 11.0 Fix Lists - IBM
Issues corrected in IBM Cognos Analytics 11.0.11.0. ... NUMBER FORMAT ON A COLUMN IN A DATA LIST, ERROR CANNOT READ PROPERTY '_IC5' OF...
Read more >
Changelog - Cypress Documentation
Hovering over a command log without a snapshot will no longer cause the error Cannot read property 'name' of null . Fixes #15816....
Read more >
Nativescript Firebase plugin - “cannot read property of null ...
After upgrading the project, I am facing a major issue with all firebase queries. **JS: Error in firebase.query: TypeError: Cannot read property ...
Read more >
CloudTest Release Notes - SOASTA- Build 6619.29
63398: (TouchTest) Locator tool issue [requires new TouchTest Driver] ... 63856: (CloudTest) Cannot read property 'textContent' of null.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found