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

Nondeterministic bug in Chrome regarding (u)int64 values #197

Closed
mibitzi opened this issue Mar 20, 2015 · 8 comments
Closed

Nondeterministic bug in Chrome regarding (u)int64 values #197

mibitzi opened this issue Mar 20, 2015 · 8 comments

Comments

@mibitzi
Copy link

mibitzi commented Mar 20, 2015

Hi,
I am generating a json on my Backend which includes a time.Duration field and I am trying to unmarshal it in gopherjs:

Playground: http://www.gopherjs.org/play/#/kdIAc8hVfH

package main

import (
    "encoding/json"
    "time"

    "github.com/gopherjs/gopherjs/js"
)

type Player struct {
    Main time.Duration
}

func main() {
    for i := 0; i < 1000; i++ {
        raw := `{"Main":1200000000000}`
        out := &Player{}

        if err := json.Unmarshal([]byte(raw), out); err != nil {
            // This error occurs very often, but not always
            js.Global.Get("console").Call("error", err.Error())
        }
    }
}

From my tests this works without issues in firefox but in chromium there is an error about ~900 of 1000 times. So it does sometimes work, but most of the time there's an error.

I'm using Chromium Version 41.0.2272.101 (64-bit) on linux.

Edit:
Internet Explorer seems to work fine as well. And Google Chrome 41 on Windows has the same issue still.

@dmitshur
Copy link
Member

Confirmed via playground link on Chrome 41.0.2272.101 on OS X. Seeing 880~920 errors per run. This is pretty bizarre.

Seeing zero errors in Firefox.

Here's a slightly modified version that shows total errors in the output box:

http://www.gopherjs.org/play/#/W9Ne2KyZSV

With it, I see that when the console is opened, I keep getting 900~ errors each time, but with console closed, I get 900~ errors first two runs, but 0 errors afterwards. o.o

@neelance
Copy link
Member

Chrome's JS optimizer is quite aggressive and sometimes it does optimizations that are wrong. It is also not deterministic. I've seen similar issues before and will try to find a workaround.

@neelance
Copy link
Member

I've tracked down the exact issue. Here is a JavaScript test case:

var f = function() {
  var a = 4294967295;
  var b = 0;
  var c = a + b;
  console.log(c, c >>> 0);
};

for (var i = 0; i < 1000; i++) {
  f();
}

After some iterations, c >>> 0 changes from 4294967295 to 0. This is a quite fundamental bug, I haven't found a workaround. Good news is that it seems to be fixed in the Chrome Canary version. So I guess we'll have to wait until the fix ships in the stable channel.

@mibitzi
Copy link
Author

mibitzi commented Mar 22, 2015

Nice. I guess then we can close this for now :)

@mibitzi mibitzi closed this as completed Mar 22, 2015
@neelance
Copy link
Member

Let's keep it open until the bug is resolved in Chrome stable, just for others who run into the same issue.

@neelance neelance reopened this Mar 22, 2015
@neelance neelance changed the title Chrome cannot json.Unmarshal int64 Nondeterministic bug in Chrome regarding (u)int64 values Mar 22, 2015
@neelance
Copy link
Member

I am using Chrome stable (version 41) and Chrome Canary (version 43). Only version 41 shows the bug. Is there someone who has Chrome beta (version 42) installed? It's not that easy to switch between release channels without messing with your system.

@mibitzi
Copy link
Author

mibitzi commented Mar 23, 2015

I don't have 42, but I noticed that in Version 40.0.2214.111 (64-bit) the bug also does not exist.
So it seems only 41 and possibly 42 are affected.

@neelance neelance modified the milestone: 1.0 Mar 26, 2015
@neelance
Copy link
Member

Chrome 42 just got released on the stable channel and the bug is fixed. Yey! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants