0

I'm trying to build a React phone app that connects to AWS once it starts up. The first time I ran the app using Expo I got an error about missing the module "Util," so I followed this separate thread to resolve that issue. Afterwards, I got another issue regarding "filesys.existsSync is not a function," so I followed this other thread to resolve that issue.

When I followed the second thread, I connected the client through a websocket protocol rather than using a certificate. After making these changes, I tested to see if the connection worked in a node.js file, and it connected without any issues. I can also confirm that the React app runs without error on Expo without the AWS code. However, as soon as I try to combine the two, I get the following error.

In Expo, I get the following error logging:


03:10
transform[stdout]: 
transform[stdout]: <--- Last few GCs --->
transform[stdout]: io[8441:0x9b1a90]    57166 ms: Mark-sweep 1387.9 (1429.3) -> 1386.5 (1430.8) MB, 3232.4 / 0.0 ms  (+ 145.9 ms in 119 steps since start of marking, biggest step 11.0 ms, walltime since start of marking 3448 ms) (average mu = 0.081, current mu = 0.022) alloca[8441:0x9b1a90]    60040 ms: Mark-sweep 1392.7 (1431.3) -> 1389.5 (1433.8) MB, 2729.3 / 0.0 ms  (+ 77.2 ms in 95 steps since start of marking, biggest step 10.8 ms, walltime since start of marking 2867 ms) (average mu = 0.056, current mu = 0.025) allocati
transform[stdout]: 
transform[stdout]: <--- JS stacktrace --->
transform[stdout]: 
transform[stdout]: ==== JS stack trace =========================================
transform[stdout]: 
transform[stdout]:     0: ExitFrame [pc: 0x74ec865452b]
transform[stdout]: Security context: 0x058c7e02ee11 <JSObject>
transform[stdout]:     1: /* anonymous */ [0xf6ddf9ef2c1] [/mnt/c/Users/aless/Desktop/UMNSVP/freya-app/new_branch/node_modules/@babel/traverse/lib/index.js:~75] [pc=0x74ec8b3ce6b](this=0x22bfe78ae6e9 <JSFunction traverse (sfi = 0x114f116c781)>,node=0x1467dbf20a49 <Node map = 0x1701e8edb8b1>,opts=0x1a7553733ca1 <Object map = 0x1b9c346b8861>,scope=0x3b66a58da481 <Scope map = 0x1b...
transform[stdout]: 
INFO
03:10
transform[stderr]: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
INFO
03:10
transform[stderr]:  1: 0x7fcaeea2d46c node::Abort() [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:10
transform[stderr]:  2: 0x7fcaeea2d4b5  [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:10
transform[stderr]:  3: 0x7fcaeec59e6a v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:10
transform[stderr]:  4: 0x7fcaeec5a0e1 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:10
transform[stderr]:  5: 0x7fcaeeff4c66  [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:10
transform[stderr]:  6: 0x7fcaef006043 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:10
transform[stderr]:  7: 0x7fcaef006930 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:10
transform[stderr]:  8: 0x7fcaef00891d v8::internal::Heap::AllocateRawWithLigthRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:10
transform[stderr]:  9: 0x7fcaef008975 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:10
transform[stderr]: 10: 0x7fcaeefd4dda v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:10
transform[stderr]: 11: 0x7fcaef26031e v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/lib/x86_64-linux-gnu/libnode.so.64]
transform[stderr]: 12: 0x74ec865452b 
INFO
03:11
transform[stdout]: 
transform[stdout]: <--- Last few GCs --->
transform[stdout]: 
transform[stdout]: [8496:0x16dfa90]    64912 ms: Scavenge 1383.0 (1422.8) -> 1382.7 (1423.3) MB, 7.6 / 0.0 ms  (average mu = 0.141, current mu = 0.013) allocation failure 
transform[stdout]: [8496:0x16dfa90]    67294 ms: Mark-sweep 1383.4 (1423.3) -> 1383.1 (1423.3) MB, 2377.6 / 0.0 ms  (average mu = 0.080, current mu = 0.007) allocation failure scavenge might not succeed
transform[stdout]: 
transform[stdout]: 
transform[stdout]: <--- JS stacktrace --->
transform[stdout]: 
transform[stdout]: ==== JS stack trace =========================================
transform[stdout]: 
transform[stdout]:     0: ExitFrame [pc: 0x276fc0c5452b]
transform[stdout]: Security context: 0x04399ea2ee11 <JSObject>
transform[stdout]:     1: visitQueue [0x343848f072f9] [/mnt/c/Users/aless/Desktop/UMNSVP/freya-app/new_branch/node_modules/@babel/traverse/lib/context.js:~94] [pc=0x276fc0f33dec](this=0x0d7bc0a5b659 <TraversalContext map = 0x97d5ee8c759>,queue=0x0d7bc0a5b6e9 <JSArray[1]>)
transform[stdout]:     2: /* anonymous */ [0x591909657f9] [/mnt/c/Users/aless/Desktop/UMNSVP/freya-app/new_branch/node_module...
transform[stdout]: 
INFO
03:11
transform[stderr]: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
INFO
03:11
transform[stderr]:  1: 0x7fc5340fd46c node::Abort() [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:11
transform[stderr]:  2: 0x7fc5340fd4b5  [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:11
transform[stderr]:  3: 0x7fc534329e6a v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:11
transform[stderr]:  4: 0x7fc53432a0e1 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:11
transform[stderr]:  5: 0x7fc5346c4c66  [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:11
transform[stderr]:  6: 0x7fc5346d6043 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:11
transform[stderr]:  7: 0x7fc5346d6930 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:11
transform[stderr]:  8: 0x7fc5346d891d v8::internal::Heap::AllocateRawWithLigthRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:11
transform[stderr]:  9: 0x7fc5346d8975 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:11
transform[stderr]: 10: 0x7fc5346a4dda v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:11
transform[stderr]: 11: 0x7fc53493031e v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/lib/x86_64-linux-gnu/libnode.so.64]
transform[stderr]: 12: 0x276fc0c5452b 
INFO
03:13
transform[stdout]: 
transform[stdout]: <--- Last few GCs --->
transform[stdout]: 
transform[stdout]: [8506:0x19f2a90]    65990 ms: Mark-sweep 1386.5 (1434.8) -> 1384.5 (1437.3) MB, 2579.9 / 0.0 ms  (average mu = 0.135, current mu = 0.007) allocation failure scavenge might not succeed
transform[stdout]: [8506:0x19f2a90]    68515 ms: Mark-sweep 1390.3 (1437.3) -> 1387.8 (1455.8) MB, 2511.2 / 0.0 ms  (average mu = 0.075, current mu = 0.005) allocation failure scavenge might not succeed
transform[stdout]: 
transform[stdout]: 
transform[stdout]: <--- JS stacktrace --->
transform[stdout]: 
transform[stdout]: ==== JS stack trace =========================================
transform[stdout]: 
transform[stdout]:     0: ExitFrame [pc: 0x21440d25452b]
transform[stdout]: Security context: 0x151eda32ee11 <JSObject>
transform[stdout]:     1: new NodePath [0x91e8a7e4669] [/mnt/c/Users/aless/Desktop/UMNSVP/freya-app/new_branch/node_modules/@babel/traverse/lib/path/index.js:~59] [pc=0x21440d4a75b7](this=0x3afbd5beda71 <NodePath map = 0x15f88580ba49>,hub=0x048270b825d9 <undefined>,parent=0x251db6f78119 <Node map = 0x15f885836291>)
transform[stdout]:     2: ConstructFrame [pc: 0x21440d199dc9]
transform[stdout]:     3: /* anonymous...
transform[stdout]: 
INFO
03:13
transform[stderr]: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
INFO
03:13
transform[stderr]:  1: 0x7fa28e94d46c node::Abort() [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:13
transform[stderr]:  2: 0x7fa28e94d4b5  [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:13
transform[stderr]:  3: 0x7fa28eb79e6a v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:13
transform[stderr]:  4: 0x7fa28eb7a0e1 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:13
transform[stderr]:  5: 0x7fa28ef14c66  [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:13
transform[stderr]:  6: 0x7fa28ef26043 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:13
transform[stderr]:  7: 0x7fa28ef26930 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:13
transform[stderr]:  8: 0x7fa28ef2891d v8::internal::Heap::AllocateRawWithLigthRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:13
transform[stderr]:  9: 0x7fa28ef28975 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:13
transform[stderr]: 10: 0x7fa28eef4dda v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:13
transform[stderr]: 11: 0x7fa28f180424 v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/lib/x86_64-linux-gnu/libnode.so.64]
transform[stderr]: 12: 0x21440d25452b 
INFO
03:14
transform[stdout]: 
transform[stdout]: <--- Last few GCs --->
transform[stdout]: 
transform[stdout]: [8516:0x902a90]    68473 ms: Scavenge 1380.1 (1421.3) -> 1379.8 (1421.8) MB, 4.9 / 0.0 ms  (average mu = 0.101, current mu = 0.033) allocation failure 
transform[stdout]: [8516:0x902a90]    68482 ms: Scavenge 1380.5 (1421.8) -> 1380.2 (1422.8) MB, 4.9 / 0.0 ms  (average mu = 0.101, current mu = 0.033) allocation failure 
transform[stdout]: [8516:0x902a90]    68490 ms: Scavenge 1380.8 (1422.8) -> 1380.5 (1423.3) MB, 4.8 / 0.0 ms  (average mu = 0.101, current mu = 0.033) allocation failure 
transform[stdout]: 
transform[stdout]: 
transform[stdout]: <--- JS stacktrace --->
transform[stdout]: 
transform[stdout]: ==== JS stack trace =========================================
transform[stdout]: 
transform[stdout]:     0: ExitFrame [pc: 0x6609d5d452b]
transform[stdout]: Security context: 0x1c8f4932ee11 <JSObject>
transform[stdout]:     1: /* anonymous */ [0xb2a7406f381] [/mnt/c/Users/aless/Desktop/UMNSVP/freya-app/new_branch/node_modules/@babel/traverse/lib/index.js:~75] [pc=0x6609d8687ab](this=0x3d6b1fee0e11 <JSFunction traverse (sfi = 0xbd7d0dec4d1)>,node=0x3f1c1c2c8599 <Node map = 0x3a29e80b98e1>,opts=0x3d6b1fee6479 <Object map = 0x3a29e80ae201>,scope=0x26e2353f0af9 <Scope map = 0x3a...
transform[stdout]: 
INFO
03:14
transform[stderr]: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
INFO
03:14
transform[stderr]:  1: 0x7f2ebd76d46c node::Abort() [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:14
transform[stderr]:  2: 0x7f2ebd76d4b5  [/lib/x86_64-linux-gnu/libnode.so.64]
transform[stderr]:  3: 0x7f2ebd999e6a v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:14
transform[stderr]:  4: 0x7f2ebd99a0e1 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:14
transform[stderr]:  5: 0x7f2ebdd34c66  [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:14
transform[stderr]:  6: 0x7f2ebdd46043 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:14
transform[stderr]:  7: 0x7f2ebdd46930 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:14
transform[stderr]:  8: 0x7f2ebdd4891d v8::internal::Heap::AllocateRawWithLigthRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:14
transform[stderr]:  9: 0x7f2ebdd48975 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:14
transform[stderr]: 10: 0x7f2ebdd14dda v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/lib/x86_64-linux-gnu/libnode.so.64]
INFO
03:14
transform[stderr]: 11: 0x7f2ebdfa031e v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/lib/x86_64-linux-gnu/libnode.so.64]
transform[stderr]: 12: 0x6609d5d452b 

It seems like something within the aws-sdk is making some sort of call that keeps failing, so it keeps retrying to make that call until its exceeded the number of times it can retry the call. I'm not sure what this would be or why it's happening, but any help would be appreciated! I have my App.js file below.

import React, {Component} from 'react';
import { Button, Dimensions, StatusBar, StyleSheet, Text, TextInput, Platform, View, Image } from 'react-native';
import VerticalViewPager from 'react-native-vertical-view-pager/src/component/VerticalViewPager';
import { NavigationContainer } from '@react-navigation/native';
import Test from './Test.js';
import Car from './Car.js';
import Menu from './Menu.js';
import Charging from './Charging.js';

import Aws from 'aws-sdk/dist/aws-sdk-react-native';
import awsIot from 'aws-iot-device-sdk';
import './shim.js';

const AWS_REGION = 'us-east-2';
const AWS_COGNITO_IDENTITY_POOL = 'us-east-2:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
const AWS_IOT_ENDPOINT = 'XXXXXXXXXXXX.iot.us-east-2.amazonaws.com';

Aws.config.region = AWS_REGION
Aws.config.credentials = new Aws.CognitoIdentityCredentials({
    IdentityPoolId: AWS_COGNITO_IDENTITY_POOL
})

export default class App extends React.Component {
    constructor(props) {
        super(props);
        this.IotConnect();
    }

    IoTConnect() {
        Aws.config.credentials.get(() => {
            const config = {}
            let client
            
            config.host = AWS_IOT_ENDPOINT
            config.protocol = 'wss'
            config.clientId = `client-${Math.floor((Math.random() * 100000) + 1)}`
            config.accessKeyId = 'XXXXXXXXXXXXXX';
            config.secretKey = 'XXXXXXXXXXXXXXXXXXX';
            config.sessionToken = Aws.config.credentials.sessionToken
            
            client = awsIot.device(config)
            
            client.on('connect', () => {
                console.log("Successful connection");
            })
               
            client.on('error', error => {
                console.log(error)
            })
        })
    }

    render() {
      return (
        <NavigationContainer>
            <VerticalViewPager showsVerticalScrollIndicator={false}>
                <Test></Test>
                <Car></Car>
                <Menu></Menu>
                <Charging></Charging>
            </VerticalViewPager>
        </NavigationContainer>
      );
    }
}

2 Answers2

0

After messing around with things for a while, I managed to figure out the issue. For whatever reason, expo/React did not like the import import Aws from 'aws-sdk/dist/aws-sdk-react-native';, so I instead changed it to import Aws from 'aws-sdk'. Even with the changed import, I could still call Aws.config, so nothing needed to change drastically with the code. I also moved the following codeblock into the IoTConnect function:

Aws.config.credentials = new Aws.CognitoIdentityCredentials({
    IdentityPoolId: AWS_COGNITO_IDENTITY_POOL
})

I'm not sure if that has an impact on how whether it'll run or not, but better safe than sorry.

I noticed that the issue only ever occurred with the import Aws from 'aws-sdk/dist/aws-sdk-react-native'; import, which suggested that it was breaking the app for some reason. I'm assuming the import was repeatedly called over and over again until there wasn't any space left within the heap.

0

I solved the same problem by adding an ignore config to babel.config.js for that specific file:

{...
 ignore: ["node_modules/aws-sdk/dist/aws-sdk-react-native.js"],
 ...}
Osman Alpay
  • 133
  • 1
  • 7