cht-core icon indicating copy to clipboard operation
cht-core copied to clipboard

Race condition in unloading contact content

Open dianabarsan opened this issue 2 years ago • 1 comments

Describe the bug Some feedback docs report this error:

Uncaught (in promise): TypeError: Cannot read properties of null (reading '_id')\nTypeError: Cannot read properties of null (reading '_id')\n    at t.<anonymous> (https://host/main.js?_sw-precache=hash:1:3077223)\n    at https://host/main.js?_sw-precache=hash:1:2623240\n    at Object.next (https://host/main.js?_sw-precache=hash:1:2623345)\n    at l (https://host/main.js?_sw-precache=hash:1:2622075)\n    at p.value (https://host/polyfills.js:1:10189)\n    at Object.onInvoke (https://host/main.js?_sw-precache=hash:1:2174490)\n    at p.value (https://host/polyfills.js:1:10128)\n    at p.value (https://host/polyfills.js:1:4280)\n    at https://host/polyfills.js:1:21025\n    at p.value (https://host/polyfills.js:1:10880)

This points to: https://github.com/medic/cht-core/blob/52605ac752bb40ab61ee1198fd7fe1bc0fbef982/webapp/src/ts/modules/contacts/contacts-content.component.ts#L256 where we don't nullcheck for validity of selectedContact before accessing the _id property.

The feedback doc was reported (unanimously) on /#/contacts, and almost half of the instances seemed to be triggered soon after the app was opened.

To Reproduce Steps to reproduce the behavior: TBD

Expected behavior No errors. We should gracefully handle not having a selected contact or the selected contact being unloaded.

Logs As above.

Environment

  • Instance: live instance
  • Browser: Webview?
  • Client platform: Android
  • App: webapp
  • Version: 3.14.x

dianabarsan avatar Apr 27 '22 10:04 dianabarsan

There are about 100 feedback docs/month due to this bug for production PiH instance.

kennsippell avatar Sep 12 '22 21:09 kennsippell

I couldn't figure out how to reproduce this. The only path to the line that throws the error is already null checked so it shouldn't be possible. However it's clear from the error message what the fix is, so to be on the safe side I've just added a null check.

garethbowen avatar Feb 13 '23 01:02 garethbowen

Ready for AT in 7603-null-check-contact

garethbowen avatar Feb 14 '23 04:02 garethbowen

Hi @garethbowen, what will be the correct way to test this ticket?

tatilepizs avatar Feb 21 '23 22:02 tatilepizs

Sorry I should have been more clear... I didn't manage to reproduce it myself (even with breakpoints and so on). If you wouldn't mind just smoke testing:

  • selecting a contact
  • deselecting them (selecting another or moving to another tab)
  • muting a contact

I think that'll be sufficient.

garethbowen avatar Feb 21 '23 22:02 garethbowen

Thank you for the details Gareth. I did a smoke test using the branch 7603-null-check-contact and create contacts, edit them, muted them, and created death reports, it and everything worked as expected. So I think that we are good and we can just merge it 🎉

tatilepizs avatar Feb 22 '23 17:02 tatilepizs

Merged!

garethbowen avatar Feb 22 '23 20:02 garethbowen