Page MenuHomePhabricator

Possible calls to setState on unmounted components
Closed, ResolvedPublicBUG REPORT

Description

Steps to Reproduce:

It's a race condition so it doesn't work every time.

  1. From the search screen, select a search result and select the "close" softkey before the article has finished loading

Actual Results:

Message in console:

Can't call "this.setState" on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

Expected Results:

The first call is cancelled when the second one is issued. The general pattern to fix this is the following

useEffect( () => {
  const handler = doApiCall()
  handler.then( data => setState(data) )
  return () => {
    // do something here that will prevent handler.then() from being called
    // since this component is unmounting
    handler.abort()
  }
}, [] )

Event Timeline

SBisson created this task.Jan 31 2020, 2:26 PM
Restricted Application added a project: Inuka-Team. · View Herald TranscriptJan 31 2020, 2:26 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
AMuigai moved this task from Backlog to Bugs on the Inuka-Team board.Feb 12 2020, 1:30 PM
AMuigai triaged this task as Medium priority.Feb 13 2020, 1:49 PM
AMuigai moved this task from Bugs to Kanban on the Inuka-Team board.Feb 26 2020, 12:56 PM
AMuigai edited projects, added Inuka-Team (Kanban); removed Inuka-Team.

This problem will be gone once this T245156: Remove random article feature before launch in LSK is done,
another place of getting race condition is on the searching page that we already handle.

I didn't even know there was a random article feature in the left soft key now (see T245438), quite a surprise.

@hueitan are you suggesting we handle T245156 first?

@eamedina random feature will be either removed or hidden in the code.

SBisson updated the task description. (Show Details)Mar 6 2020, 3:36 PM

It's a general issue with our API calls. I updated the description with an example other than the random feature.

hueitan added a comment.EditedMar 6 2020, 4:27 PM

Thanks @SBisson got it! yes I can see this is a general issue now.

hueitan claimed this task.Mar 9 2020, 11:46 AM
hueitan moved this task from Ready for Dev to Code Review on the Inuka-Team (Kanban) board.

Changes were made to fix this issue but I would like to keep this task open and revisit the solution when we can.

The issue was fixed in a way that is heavily dependent on the specific features (search, read article) and the navigation order between those. If we change it or add features it is likely to come back. The deterministic way to fix it is by ensuring that components that depend on data cancel their own requests when unmounting.

SBisson moved this task from Backlog to Bugs on the Inuka-Team board.Mar 11 2020, 5:51 PM
AMuigai moved this task from Bugs to Kanban on the Inuka-Team board.Mar 19 2020, 10:49 AM
AMuigai edited projects, added Inuka-Team (Kanban); removed Inuka-Team.
SBisson removed hueitan as the assignee of this task.Mar 19 2020, 1:50 PM
AMuigai moved this task from Backlog to Bugs on the Inuka-Team board.Apr 6 2020, 1:15 PM
AMuigai moved this task from Bugs to Next up on the Inuka-Team board.May 12 2020, 7:35 PM
AMuigai moved this task from Next up to Kanban on the Inuka-Team board.May 13 2020, 11:34 AM
AMuigai edited projects, added Inuka-Team (Kanban); removed Inuka-Team.
SBisson claimed this task.May 20 2020, 7:26 PM
SBisson moved this task from Ready for Dev to Dev on the Inuka-Team (Kanban) board.
hueitan moved this task from Code Review to QA on the Inuka-Team (Kanban) board.May 26 2020, 10:11 PM
Jpita added a subscriber: Jpita.

tested on T253465

AMuigai closed this task as Resolved.Jun 3 2020, 1:27 PM