ApplicationInsights-JS icon indicating copy to clipboard operation
ApplicationInsights-JS copied to clipboard

[BUG] TypeError: Cannot read properties of null (reading '0')

Open ethan-bernstein opened this issue 1 year ago • 1 comments

In Outlook, from telemetry we are seeing hundreds of thousands of errors a week "TypeError: Cannot read properties of null (reading '0')" with callstack

webpack://owa/node_modules/@microsoft/1ds-post-js/dist-es5/HttpManager.js sendType 536 webpack://owa/node_modules/@microsoft/1ds-post-js/dist-es5/HttpManager.js _canSendPayload 456 webpack://owa/node_modules/@microsoft/1ds-post-js/dist-es5/PostChannel.js sendType 482 webpack://owa/node_modules/@microsoft/1ds-post-js/dist-es5/PostChannel.js _sendEventsForLatencyAndAbove 518 webpack://owa/node_modules/@nevware21/ts-utils/build/es5/mod/funcs/funcs.js apply 68 webpack://owa/node_modules/@nevware21/ts-utils/build/es5/mod/timer/timeout.js fnApply 20

It looks like we are calling sendEventsForLatencyAndAbove even though _httpManager is not initialized.

ethan-bernstein avatar Jul 10 '24 23:07 ethan-bernstein

Which version are you using?

As this is an internal function, it's only triggered (or should) via a timer when it has added items to be batched (which only occurs after everything has been initialized successfully) and the httpManager is created at the point of construction and also initialized as part of the SDK / post channel.

The only possible scenarios I can possible spot where it's currently possible to cause this to be called via a timer are

  • You have called the unload() function which tears down the SDK (But I don't believe that Office is using this) and this generally flushes the queues and stops all timers.
  • You are calling flush() but the SDK is not initialized <-- I suspect this is the case. While we provide the flush() function for some edge cases we don't recommend that anyone call it unless we have discussed and not found some other solution.
    • This is currently not checking if the SDK has been initialized so this "seems" like the most likely scenario, and based on the line number 518, this is "close" to where the current version of the SDK's flush() function is located.
    • So either please check if the SDK is initialized sdk.isInitialized() first or just don't call flush() as we handle all of the page unload events and effectively call this internally in response to the page navigating away.

MSNev avatar Jul 11 '24 19:07 MSNev

This Issue will be closed in 30 days. Please remove the "Stale" label or comment to avoid closure with no action.

github-actions[bot] avatar May 05 '25 23:05 github-actions[bot]