Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

takeHeapSnapshot in node inspect creates corrupted JSON #56

Closed

Description

@aleksanderlech
  • Version: v8.8.1
  • Platform: Darwin 17.3.0 Darwin Kernel Version 17.3.0: Thu Nov 9 18:09:22 PST 2017; root:xnu-4570.31.3~1/RELEASE_X86_64 x86_64
  • Subsystem: node inspect

I am trying to use "node inspect" to attach to the already running node process to collect the heap dump. Using the command:

takeHeapSnapshot(filepath = 'node.heapsnapshot') Take a heap snapshot and save to disk as JSON.

The command seems to be completed successfully.

debug> takeHeapSnapshot(filepath = 'node.heapsnapshot')
Heap snaphost prepared.
Wrote snapshot: /Users/aleksander/node.heapsnapshot

But afterwards I am trying to open it in "Node.js V8 --inspector Manager (NiM) 0.14.5" it throws the following error:

An error occurred when a call to method 'buildSnapshot' was requested
TypeError: Cannot read property 'length' of undefined
    at HeapSnapshotWorker.JSHeapSnapshot.initialize (chrome-devtools://devtools/bundled/heap_snapshot_worker.js?experiments=true&v8only=true&ws=localhost:9229/803f37dc-c1b9-409f-8705-530077f269f7:897:1641)
    at new HeapSnapshotWorker.JSHeapSnapshot (chrome-devtools://devtools/bundled/heap_snapshot_worker.js?experiments=true&v8only=true&ws=localhost:9229/803f37dc-c1b9-409f-8705-530077f269f7:1090:412)
    at HeapSnapshotWorker.HeapSnapshotLoader.buildSnapshot (chrome-devtools://devtools/bundled/heap_snapshot_worker.js?experiments=true&v8only=true&ws=localhost:9229/803f37dc-c1b9-409f-8705-530077f269f7:1197:85)
    at HeapSnapshotWorker.HeapSnapshotWorkerDispatcher.dispatchMessage (chrome-devtools://devtools/bundled/heap_snapshot_worker.js?experiments=true&v8only=true&ws=localhost:9229/803f37dc-c1b9-409f-8705-530077f269f7:1247:509)

When I open the generated dump it seems to be a corrupted JSON ending prematurely with:

",2,8443,81187,32,1,0
,1,46,81189,32,"

Is this a node inspect bug? I am able to succesfully connect to the same instance of node by the browser and use the "Take heap snapshot" function where the generated dump opens without any problems. Also noticed that the properly generated dump has about 80MB where the corrupted one only 800K.

I thought that maybe I am doing something wrong but since no error is reported and we end up with the corrupted JSON this seems to be an issue...

Activity

  1. addaleax commented on Jan 17, 2018

    @addaleax
    Member

    Is this a node inspect bug?

    Yeah, I think so. The issue is that node-inspect think the expected output size is given by the total field of the heap snapshot stats, but in reality it’s the item count, not the data length.

    I think the only way to reliably tell whether the addHeapSnapshotChunk data stream has ended is actually inspecting the JSON data itself and looking for the closing }. :/

  2. aleksanderlech commented on Jan 18, 2018

    @aleksanderlech
    Author

    I did that and it this is the way file ends:

    ",2,8443,81187,32,1,0 ,1,46,81189,32,"

    which makes it invalid JSON for sure :)

  3. added a commit that references this issue on Jan 18, 2018
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