Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

JavaScript heap out of memory #233

Closed

Description

@aseyfpour

Hi

I'm trying to subscribe to a stream using resend option. Everything goes well but after a while, it crashes.

streamr-client: 5.1.0

Stacktrace:

<--- Last few GCs --->

[2968:0000021AA9CE65C0]   362454 ms: Mark-sweep 2035.3 (2073.9) -> 2029.6 (2059.1) MB, 855.3 / 0.0 ms  (+ 862.9 ms in 233 steps since start of marking, biggest step 36.1 ms, walltime since start of marking 1943 ms) (average mu = 0.186, curre
nt mu = 0.116)[2968:0000021AA9CE65C0]   364209 ms: Mark-sweep 2036.5 (2059.1) -> 2025.8 (2053.1) MB, 1265.2 / 0.0 ms  (+ 388.4 ms in 109 steps since start of marking, biggest step 47.6 ms, walltime since start of marking 1755 ms) (average mu
 = 0.139, current mu = 0.058

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 00007FF69653770D]
    1: StubFrame [pc: 00007FF6964E70DC]
Security context: 0x02f6497808d1 <JSObject>
    2: /* anonymous */ [000003C11D8E3A01] [D:\Streamr\data-receiver\node_modules\streamr-client\src\subscribe\OrderMessages.js:~33] [pc=0000011ACAA8E7DA](this=0x003d5c513709 <EventEmitter map = 0000032521B25699>,0x022f89d542a1 <MessageRef ma
p = 0000032521B21549>,0x0199f1059a39 <MessageRef map = 0000032521B21549>,0x03...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF6959246CF napi_wrap+113583
 2: 00007FF6958CF7C6 v8::base::CPU::has_sse+66646
 3: 00007FF6958D05C6 v8::base::CPU::has_sse+70230
 4: 00007FF6960E42AE v8::Isolate::ReportExternalAllocationLimitReached+94
 5: 00007FF6960CC381 v8::SharedArrayBuffer::Externalize+833
 6: 00007FF695F988CC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1436
 7: 00007FF695FA3B00 v8::internal::Heap::ProtectUnprotectedMemoryChunks+1312
 8: 00007FF695FA0624 v8::internal::Heap::PageFlagsAreConsistent+3204
 9: 00007FF695F95E23 v8::internal::Heap::CollectGarbage+1283
10: 00007FF695F94494 v8::internal::Heap::AddRetainedMap+2452
11: 00007FF695FB569D v8::internal::Factory::NewFillerObject+61
12: 00007FF695D1BF21 v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+1665
13: 00007FF69653770D v8::internal::SetupIsolateDelegate::SetupHeap+546637
14: 00007FF6964E70DC v8::internal::SetupIsolateDelegate::SetupHeap+217372
15: 0000011ACAA8E7DA

Code:

import {StreamrClient} from "streamr-client";

const stream_id = "KT1OgUisRZq_DOEoKz3Q9Q"
const client = new StreamrClient({
    auth: {
        privateKey: 'MY_PRIVATE_KEY'
    }
});

(async () => {
    let count = 0;
    const now = new Date(new Date().toISOString().slice(0, 10)).getTime();
    client.subscribe({
        streamId: stream_id,
        resend: {
            from: {
                timestamp: 1599782400000
            },
            to: {
                timestamp: now,
            }
        }
    }, async (message, metadata) => {
        count++;
        console.log(`Count: ${count}`)
    }).then(() => {
        console.log(`Subscribed to stream ${stream_id}`)
    })
})();

Activity

  1. timoxley commented on Mar 23, 2021

    @timoxley
    Contributor

    @aseyfpour thanks for the report. There may be a memory leak, I will investigate.

    but after a while, it crashes.

    How long?

    Roughly how many messages do you have and what kind of content is in them? Can you post some example messages?

  2. timoxley commented on Mar 23, 2021

    @timoxley
    Contributor

    @aseyfpour specifically, does the script above cause the error for you, exactly as-is, with the only change being adding of the privateKey?

  3. aseyfpour commented on Mar 24, 2021

    @aseyfpour
    ContributorAuthor

    @aseyfpour thanks for the report. There may be a memory leak, I will investigate.

    but after a while, it crashes.

    How long?

    Roughly how many messages do you have and what kind of content is in them? Can you post some example messages?

    After about 60K message.

    Sample data:

    {
      header: {
        module: 'general_surfing',
        function: 'content',
        collector: 'pageInfo',
        id: '52e682ee-13b2-4e18-8269-498b9fa7c04a',
        category: 'General',
        privacyLevel: 3,
        anonymityLevel: 2,
        version: '1.2.0'
      },
      data: {
        title: 'aerogarden mason jar - Google Search',
        location: 'https://www.google.com',
        referrer: 'https://www.google.com'
      },
      identity: {
        uid: 'aa8ce621bc13c9633833586be023c3213313837fa983c31b0d1ef9c648f0e00f',
        country: 'United States',
        gender: 'Male',
        age: '30-40',
        income: '25-50K',
        agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
        platform: { os: 'win' },
        language: 'en-US'
      }
    }
    
  4. aseyfpour commented on Mar 24, 2021

    @aseyfpour
    ContributorAuthor

    @aseyfpour specifically, does the script above cause the error for you, exactly as-is, with the only change being adding of the privateKey?

    Yes, I tested with this script twice before I submit this issue. Both times this problem occurred.

  5. timoxley commented on Mar 24, 2021

    @timoxley
    Contributor

    @aseyfpour

    Can you add me as a subscriber to your stream so I can debug it?

    1. Go to your stream settings: https://streamr.network/core/streams/KT1OgUisRZq_DOEoKz3Q9Q
    2. Click Share (top right)
    3. Paste this address into the UserID box: 0x58aE1e118Cd893a0Af51311AB486ce4968be79b6
    4. Press the + button
    5. Check you're only granting get + subscribe permissions
    6. Click the Save button (bottom right)
  6. timoxley commented on Mar 24, 2021

    @timoxley
    Contributor

    @aseyfpour nevermind, I figured out a way to reproduce using other data.

    The specific thing that triggers this is a resend containing a massive number of data points, but we shouldn't be crashing regardless, there's something in our system that's holding onto references longer than it should.

    Until I figure out a fix, one workaround would be to use resend: { last: NUM_MESSAGES } or reduce the from/to range to something smaller.

  7. timoxley commented on Mar 25, 2021

    @timoxley
    Contributor

    @aseyfpour can you please try again using streamr-client@5.2.0-beta and let me know how it goes?

  8. aseyfpour commented on Mar 27, 2021

    @aseyfpour
    ContributorAuthor

    @timoxley Sorry for being late, I've been testing this version. I repeated the test several times and everything is OK with this version and I received more than 100K messages each time, but something has changed in the test environment. When I reported the issue, I received 60K messages in less than 10 minutes, but now it takes more than 3 hours to reach this amount (every time). I guess Streamr network speed is slower than before, so maybe my tests are not valid.

  9. aseyfpour commented on Mar 29, 2021

    @aseyfpour
    ContributorAuthor

    I test it again today, It fetches more than 90K messages in less than 20 minutes. I think the problem is solved.
    Thanks to @timoxley

  10. timoxley commented on Apr 1, 2021

    @timoxley
    Contributor

    🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions