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

Object::PreviewEntries returns incorrect results for Set Iterator #24053

Closed
RbertKo opened this issue Nov 3, 2018 · 16 comments
Closed

Object::PreviewEntries returns incorrect results for Set Iterator #24053

RbertKo opened this issue Nov 3, 2018 · 16 comments
Labels
v8 engine Issues and PRs related to the V8 dependency.

Comments

@RbertKo
Copy link

RbertKo commented Nov 3, 2018

  • Version: 10.10 -> 11.0 this two version have bug too
  • Platform: IDE : vscode
  • Subsystem:
let set = new Set();
set.add(1); 
set.add(2); 
set.add(3);
set.add(1); 
set.add(2); 
set.add(3);
set.delete(1);
console.log( set.size );
console.log( set.has(3) );
console.log( set.has(2) );
console.log( set.has(1));
console.log( set.keys());
console.log( set.values() );
console.log( set.entries() );

return :

2
true
true
false
[Set Iterator] { 3 }
[Set Iterator] { 3 }

I added 1, 2, 3 in 'set' instance. and I deleted '2'.
so, 'set' have '2', '3' element, but 'set' return values only '3'.
set.has(2) show 'true'!

10.10 version had a bug, so i upgraded my node version to 11.0, but can't resolve it.

@devsnek
Copy link
Member

devsnek commented Nov 3, 2018

It looks like the inspector is wrong. The set still has 2 and 3 if you actually iterate over it: for (const element of a) { console.log(e); }

cc @BridgeAR

@RbertKo
Copy link
Author

RbertKo commented Nov 3, 2018

It looks like the inspector is wrong. The set still has 2 and 3 if you actually iterate over it: for (const element of a) { console.log(e); }

cc @BridgeAR

yeah, i think too. so, set.had(2) is returned 'true'.

@devsnek
Copy link
Member

devsnek commented Nov 3, 2018

further debugging reveals that the problem lies in Object::PreviewEntries. @nodejs/v8

@devsnek devsnek added the v8 engine Issues and PRs related to the V8 dependency. label Nov 3, 2018
@ghost
Copy link

ghost commented Nov 4, 2018

After all the addition to the set, the set looks like this: Set { 1, 2, 3 }
Next you execute: set.delete(1); which removes the element 1 from the set so now the set looks like this: Set { 2, 3 }
Isn't this the right behavior?
The set.delete function takes the value which it removes from the set and that's what it is doing here( In the snippet written in the description), removing 1 from the set

@devsnek
Copy link
Member

devsnek commented Nov 4, 2018

@Flowkrad the issue is the util.inspect output of the set iterator.

const a = new Set([1, 2, 3]);
a.delete(1);
util.inspect(a); // Set { 2, 3 }
util.inspect(a.keys()); // [Set Iterator] { 3 }

^ @addaleax @nodejs/v8 minimal repro btw

@ghost
Copy link

ghost commented Nov 4, 2018

Thank for pointing that out (^_^)
P.S. Got confused when RobertKo replied with:

yeah, i think too. so, set.had(2) is returned 'true'.

@devsnek devsnek changed the title Set Object have a bug. I think also iterator bug. Object::PreviewEntries returns incorrect results for Set Iterator Nov 4, 2018
@shobhitchittora
Copy link
Contributor

Yeah! Happens with Map iterator too. Any idea how to debug in c++. I'm using lldb and find it difficult to inspect values.

static void PreviewEntries(const FunctionCallbackInfo<Value>& args) {

@addaleax
Copy link
Member

addaleax commented Nov 8, 2018

@shobhitchittora Have you seen https://github.com/nodejs/llnode/? It’s pretty neat for debugging Node/V8 code.

@shobhitchittora
Copy link
Contributor

@addaleax Sounds cool! Thanks. Let me have a look at it.

@shobhitchittora
Copy link
Contributor

On further inspection, this happens only when you delete the first value in a set or a map.

const s = new Set([1,2,3])

// this creates problem
s.delete(1)
s.keys() // [3]

// while this works fine
s.delete(2)
s.keys()

@shobhitchittora
Copy link
Contributor

shobhitchittora commented Nov 8, 2018

More investigation shows that the latest Chrome also has the same behavior. Checking v8 bug list for the same.

Reported the same to upstream v8 - https://bugs.chromium.org/p/v8/issues/detail?id=8433.

Edit - v8 api code pointer - https://github.com/v8/v8/blob/master/src/api.cc#L9512

@addaleax
Copy link
Member

addaleax commented Nov 8, 2018

@shobhitchittora Okay, sounds like nothing we could fix on the Node side? If you end up fixing this in V8 and want any guidance on how to submit a patch to them (this can be tricky if you’re not familiar with it), just let us know. :)

@hashseed
Copy link
Member

hashseed commented Nov 8, 2018

I already have a fix. Coming up soon.

@shobhitchittora
Copy link
Contributor

shobhitchittora commented Nov 12, 2018

Hey @addaleax The fix has been merged as per this - https://chromium.googlesource.com/v8/v8/+/88f8fe19a863c6392bd296faf86c06eff2a41bc1.

How can we now get the dep updated in node?

@Trott
Copy link
Member

Trott commented Nov 20, 2018

@hashseed At this point, is there anything left to do besides wait for your fix to end up in a V8 release, and then wait for Node.js to pick up that V8 release? /cc @addaleax

@targos
Copy link
Member

targos commented Nov 24, 2018

Fixed in #24514

@targos targos closed this as completed Nov 24, 2018
targos pushed a commit that referenced this issue Nov 24, 2018
Original commit message:

    Fix collection iterator preview with deleted entries

    We used to assume that we know the remaining entries returned by the
    iterator based on the current index. However, that is not accurate,
    since entries skipped by the current index could be deleted.

    In the new approach, we allocate conservatively and shrink the result.

    R=neis@chromium.org

    Bug: v8:8433
    Change-Id: I38a3004dc3af292daabb454bb76f38d65ef437e8
    Reviewed-on: https://chromium-review.googlesource.com/c/1325966
    Commit-Queue: Yang Guo <yangguo@chromium.org>
    Reviewed-by: Georg Neis <neis@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#57360}

Refs: v8/v8@88f8fe1

PR-URL: #24514
Refs: #24053
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
targos pushed a commit that referenced this issue Nov 24, 2018
Original commit message:

    Fix collection iterator preview with deleted entries

    We used to assume that we know the remaining entries returned by the
    iterator based on the current index. However, that is not accurate,
    since entries skipped by the current index could be deleted.

    In the new approach, we allocate conservatively and shrink the result.

    R=neis@chromium.org

    Bug: v8:8433
    Change-Id: I38a3004dc3af292daabb454bb76f38d65ef437e8
    Reviewed-on: https://chromium-review.googlesource.com/c/1325966
    Commit-Queue: Yang Guo <yangguo@chromium.org>
    Reviewed-by: Georg Neis <neis@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#57360}

Refs: v8/v8@88f8fe1

PR-URL: #24514
Refs: #24053
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
rvagg pushed a commit that referenced this issue Nov 28, 2018
Original commit message:

    Fix collection iterator preview with deleted entries

    We used to assume that we know the remaining entries returned by the
    iterator based on the current index. However, that is not accurate,
    since entries skipped by the current index could be deleted.

    In the new approach, we allocate conservatively and shrink the result.

    R=neis@chromium.org

    Bug: v8:8433
    Change-Id: I38a3004dc3af292daabb454bb76f38d65ef437e8
    Reviewed-on: https://chromium-review.googlesource.com/c/1325966
    Commit-Queue: Yang Guo <yangguo@chromium.org>
    Reviewed-by: Georg Neis <neis@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#57360}

Refs: v8/v8@88f8fe1

PR-URL: #24514
Refs: #24053
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
targos pushed a commit to targos/node that referenced this issue Dec 4, 2018
Original commit message:

    Fix collection iterator preview with deleted entries

    We used to assume that we know the remaining entries returned by the
    iterator based on the current index. However, that is not accurate,
    since entries skipped by the current index could be deleted.

    In the new approach, we allocate conservatively and shrink the result.

    R=neis@chromium.org

    Bug: v8:8433
    Change-Id: I38a3004dc3af292daabb454bb76f38d65ef437e8
    Reviewed-on: https://chromium-review.googlesource.com/c/1325966
    Commit-Queue: Yang Guo <yangguo@chromium.org>
    Reviewed-by: Georg Neis <neis@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#57360}

Refs: v8/v8@88f8fe1

PR-URL: nodejs#24514
Refs: nodejs#24053
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
pull bot pushed a commit to shakir-abdo/node that referenced this issue Dec 6, 2018
Original commit message:

    Fix collection iterator preview with deleted entries

    We used to assume that we know the remaining entries returned by the
    iterator based on the current index. However, that is not accurate,
    since entries skipped by the current index could be deleted.

    In the new approach, we allocate conservatively and shrink the result.

    R=neis@chromium.org

    Bug: v8:8433
    Change-Id: I38a3004dc3af292daabb454bb76f38d65ef437e8
    Reviewed-on: https://chromium-review.googlesource.com/c/1325966
    Commit-Queue: Yang Guo <yangguo@chromium.org>
    Reviewed-by: Georg Neis <neis@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#57360}

Refs: v8/v8@88f8fe1

PR-URL: nodejs#24514
Refs: nodejs#24053
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
refack pushed a commit to refack/node that referenced this issue Jan 14, 2019
Original commit message:

    Fix collection iterator preview with deleted entries

    We used to assume that we know the remaining entries returned by the
    iterator based on the current index. However, that is not accurate,
    since entries skipped by the current index could be deleted.

    In the new approach, we allocate conservatively and shrink the result.

    R=neis@chromium.org

    Bug: v8:8433
    Change-Id: I38a3004dc3af292daabb454bb76f38d65ef437e8
    Reviewed-on: https://chromium-review.googlesource.com/c/1325966
    Commit-Queue: Yang Guo <yangguo@chromium.org>
    Reviewed-by: Georg Neis <neis@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#57360}

Refs: v8/v8@88f8fe1

PR-URL: nodejs#24514
Refs: nodejs#24053
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
refack pushed a commit to refack/node that referenced this issue Jan 14, 2019
Original commit message:

    Fix collection iterator preview with deleted entries

    We used to assume that we know the remaining entries returned by the
    iterator based on the current index. However, that is not accurate,
    since entries skipped by the current index could be deleted.

    In the new approach, we allocate conservatively and shrink the result.

    R=neis@chromium.org

    Bug: v8:8433
    Change-Id: I38a3004dc3af292daabb454bb76f38d65ef437e8
    Reviewed-on: https://chromium-review.googlesource.com/c/1325966
    Commit-Queue: Yang Guo <yangguo@chromium.org>
    Reviewed-by: Georg Neis <neis@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#57360}

Refs: v8/v8@88f8fe1

PR-URL: nodejs#24514
Refs: nodejs#24053
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
addaleax pushed a commit to addaleax/node that referenced this issue May 26, 2019
Original commit message:

    Fix collection iterator preview with deleted entries

    We used to assume that we know the remaining entries returned by the
    iterator based on the current index. However, that is not accurate,
    since entries skipped by the current index could be deleted.

    In the new approach, we allocate conservatively and shrink the result.

    R=neis@chromium.org

    Bug: v8:8433
    Change-Id: I38a3004dc3af292daabb454bb76f38d65ef437e8
    Reviewed-on: https://chromium-review.googlesource.com/c/1325966
    Commit-Queue: Yang Guo <yangguo@chromium.org>
    Reviewed-by: Georg Neis <neis@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#57360}

[The backport to v10.x resolves merge conflicts due to a different way
of accessing the “hole” value in V8, different signatures of the
`Handle` constructor and the `Shrink()` method, and neighbouring-line
conflicts in the test file.]

Refs: v8/v8@88f8fe1
Fixes: nodejs#27882
PR-URL: nodejs#24514
Refs: nodejs#24053
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
BethGriggs pushed a commit that referenced this issue Jun 6, 2019
Original commit message:

    Fix collection iterator preview with deleted entries

    We used to assume that we know the remaining entries returned by the
    iterator based on the current index. However, that is not accurate,
    since entries skipped by the current index could be deleted.

    In the new approach, we allocate conservatively and shrink the result.

    R=neis@chromium.org

    Bug: v8:8433
    Change-Id: I38a3004dc3af292daabb454bb76f38d65ef437e8
    Reviewed-on: https://chromium-review.googlesource.com/c/1325966
    Commit-Queue: Yang Guo <yangguo@chromium.org>
    Reviewed-by: Georg Neis <neis@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#57360}

[The backport to v10.x resolves merge conflicts due to a different way
of accessing the “hole” value in V8, different signatures of the
`Handle` constructor and the `Shrink()` method, and neighbouring-line
conflicts in the test file.]

Refs: v8/v8@88f8fe1
Fixes: #27882

Backport-PR-URL: #27894
PR-URL: #24514
Refs: #24053
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

7 participants