Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] setInterval/setTimeout causes the app to crash, May be the problem with RCTTiming.m #26995

Closed
bashen1 opened this issue Oct 25, 2019 · 3 comments
Labels
Bug Resolution: Locked This issue was locked by the bot.

Comments

@bashen1
Copy link

bashen1 commented Oct 25, 2019

React Native version:
System:
OS: macOS 10.15
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 63.55 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.10.0 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.12.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
Android SDK:
API Levels: 23, 25, 26, 27, 28, 29
Build Tools: 25.0.2, 27.0.3, 28.0.3, 29.0.1, 29.0.2
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5900203
Xcode: 10.3/10G8 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.2 => 0.61.2
npmGlobalPackages:
react-native-cli: 2.0.1

Steps To Reproduce

  1. react-native init demo
  2. modify demo/App.js
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, {PureComponent} from 'react';
import {
    SafeAreaView,
    ScrollView,
    View,
    Text,
    StatusBar,
} from 'react-native';

class App extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            num: 0
        }
    }

    componentDidMount(): * {
        this.timer = setInterval(() => {
            this.setState({
                num: this.state.num + 1
            })
        }, 1000)
    }

    render(): boolean | number | string | React$Element<*> | React$Portal | Iterable | null {
        return (
            <>
                <StatusBar barStyle="dark-content"/>
                <SafeAreaView>
                    <ScrollView
                        contentInsetAdjustmentBehavior="automatic"
                       >
                      <View>
                        <Text>{this.state.num}</Text>
                      </View>
                    </ScrollView>
                </SafeAreaView>
            </>
        )
    }
}

export default App;
  1. Keep the application foreground(background). Device lock screen, then unlock for a few minutes, app crash,sometimes will show redscreen「Timed out waiting for modules to be invalidated」

LOG

Process exited: <FBApplicationProcess: 0x11d5fb5f0; application<org.reactjs.native.example.demo>:16512> -> <RBSProcessExitContext; specific: <RBSProcessExitStatus; domain: runningboard (15); code: 0x2182baad>; terminationContext: <RBSTerminateContext: 0x280ee4840; code: 0x2182BAAD; explanation: "Timed-out waiting for process [application<org.reactjs.native.example.demo>:16512] to invalidate assertion with identifier 26-16512-127410 and explanation 'Shared Background Assertion 2 for org.reactjs.native.example.demo'. Direct this report to owners of that process"; reportType: 0; maxRole: 7; maxTerminationResistance: 3>>
@bashen1 bashen1 added the Bug label Oct 25, 2019
@mmahdigh
Copy link

I can't reproduce this issue.
Could you give us more details? like on what device you run your app on (emulator or physical)?

@bashen1
Copy link
Author

bashen1 commented Oct 28, 2019

@mmahdigh

Info
Phone: iPhone 7 128GB(Physical)
OS: iOS 13.1.3

Setps

  1. react-native init demo
  2. modify demo/App.js just like
import React, {PureComponent} from 'react';
import {
    SafeAreaView,
    ScrollView,
    View,
    Text,
    StatusBar,
} from 'react-native';

class App extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            num: 0
        }
    }

    componentDidMount(): * {
        this.timer = setInterval(() => {
            this.setState({
                num: this.state.num + 1
            })
        }, 1000)
    }

    render(): boolean | number | string | React$Element<*> | React$Portal | Iterable | null {
        return (
            <>
                <StatusBar barStyle="dark-content"/>
                <SafeAreaView>
                    <ScrollView
                        contentInsetAdjustmentBehavior="automatic"
                       >
                      <View>
                        <Text>{this.state.num}</Text>
                      </View>
                    </ScrollView>
                </SafeAreaView>
            </>
        )
    }
}

export default App;
  1. run debug/release on the physical device
  2. app background with the device not lockscreen OR foreground with the device lockscreen
  3. wait just about one minutes or more, app crash

Android is OK

@bashen1 bashen1 changed the title setInterval/setTimeout causes the app to crash 【iOS】setInterval/setTimeout causes the app to crash, May be the problem with RCTTiming.m Oct 31, 2019
bashen1 referenced this issue Oct 31, 2019
Summary:
Related #23674, in that PR, we imported background timer support, but it's not sufficient, I think the reason that works is because it enable the `Background Modes` and do some background tasks, for the users who don't enable it, timer would pause immediately before goes into background.

To fix it, we can mark a background task when goes into background, it can keep app active for minutes, try best to support timing when in background.

cc. cpojer .

## Changelog

[iOS] [Fixed] - Timing: Fixes timer when app get into background
Pull Request resolved: #24649

Differential Revision: D15554451

Pulled By: cpojer

fbshipit-source-id: a33f7afe6b63d1a4fefcb7098459aee0c09145da
@radko93
Copy link
Contributor

radko93 commented Oct 31, 2019

Duplicate of #26696

@radko93 radko93 marked this as a duplicate of #26696 Oct 31, 2019
@radko93 radko93 closed this as completed Oct 31, 2019
@radko93 radko93 changed the title 【iOS】setInterval/setTimeout causes the app to crash, May be the problem with RCTTiming.m [iOS] setInterval/setTimeout causes the app to crash, May be the problem with RCTTiming.m Oct 31, 2019
radko93 added a commit that referenced this issue Oct 31, 2019
radko93 added a commit that referenced this issue Oct 31, 2019
radko93 added a commit that referenced this issue Oct 31, 2019
This PR reverts commit 3382984 that is causing #26696 #26995.
facebook-github-bot pushed a commit that referenced this issue Nov 5, 2019
…27073)

Summary:
This PR reverts commit 3382984 that is causing #26696 #26995.
> app would be closed immediately after going to background on iOS 13.1/13.2 and was investigated by minhtc #26696 (comment). The commit that is being reverted is apparently causing the app to be closed immediately. This has to be reverted in master separately as the file differs there.

Similar PR for 0.61. branch #27065

## Changelog

[iOS] [Fixed] - Fix apps crashing on iOS 13.x when running timer in the background
Pull Request resolved: #27073

Test Plan: Try [this](3382984#commitcomment-35745287) snippet on iOS 13.1/13.2, the app should not crash anymore

Differential Revision: D18323679

Pulled By: cpojer

fbshipit-source-id: 3af7036a0e1d3811924e581c649b16e5a4667e83
@facebook facebook locked as resolved and limited conversation to collaborators Oct 2, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants