go1beta2 gob issues?

65 views
Skip to first unread message

Francis Li

unread,
Feb 14, 2012, 9:23:23 PM2/14/12
to google-appengine-go
Forgive me if I'm a bit light on specifics- I'm quite new to the Go
language. I was experimenting with AppEngine Go shortly before the
new go1beta releases started coming out.

I just tried migrating my code to go1beta2- after running go tool fix
and making some minor changes, everything seemed to be working fine...
except for some wierd unpredictable behavior with gob. I'm using gob
to serialize a map[string]interface{} which is base64 encoded and
stored in a cookie (and vice versa). This was working fine in the r60
release version, but since migrating to go1beta, sometimes it works,
and sometimes it doesn't.

Sometimes, I'll simply get an incomplete map of the data I serialized
before (key/value pairs missing). Other times, I'll get an error like:

gob: name not registered for interface: "otice\x06string\f#\x00!
Controllers.Signin.Create.Success\aUserKey\x06string\f%\x00#agxkZXZ-
bGlmdC1yZXByCgsSBFVzZXIYAQw\x00\x00\x00\x00\x00\x00\x00"

In this case, there was another map[string]interface{} inside the
serialized map, which is not being deserialized correctly.

I'm going to try and see if I can pin this down better- hopefully a
standalone .go file running on the command line that demonstrates the
issue.

In the meantime, is anyone else seeing any similar issues? I've
searched the Go issue tracker for gob related issues, but nothing
similar has been reported yet...

Sincerely,
Francis

David Symonds

unread,
Feb 14, 2012, 9:27:11 PM2/14/12
to Francis Li, google-appengine-go
On Wed, Feb 15, 2012 at 1:23 PM, Francis Li <fra...@tikitakistudio.com> wrote:

> gob: name not registered for interface: "otice\x06string\f#\x00!
> Controllers.Signin.Create.Success\aUserKey\x06string\f%\x00#agxkZXZ-
> bGlmdC1yZXByCgsSBFVzZXIYAQw\x00\x00\x00\x00\x00\x00\x00"

That sounds like you're asking gob to deal with a concrete type it
hasn't seen before. You need to use gob.Register
(http://weekly.golang.org/pkg/encoding/gob/#Register) on concrete
types that will be passed to gob inside an interface.


Dave.

Francis Li

unread,
Feb 14, 2012, 10:33:24 PM2/14/12
to google-appengine-go
Thanks for the tip, I'll look into it- although, I'm pretty sure I'm
only storing strings and other map[string]interface{} objects (that
are only storing strings) in this map. I am already registering
map[string]interface{} in init(), but I'll experiment and test a bit
more...

Francis

Francis Li

unread,
Feb 14, 2012, 11:04:14 PM2/14/12
to google-appengine-go
Ok, here's a short Go program that reproduces this issue for me, I put
it in a file called gob_test.go:

package main

import (
"bytes"
"encoding/gob"
"fmt"
)

func init() {
gob.Register(make(map[string]interface{}))
}

func main() {
data := make(map[string]interface{})
subdata := make(map[string]interface{})
subdata["bar"] = "baz"
data["foo"] = subdata
data["test"] = "testing"
fmt.Println("Data before:", data)

buffer := new(bytes.Buffer)
encoder := gob.NewEncoder(buffer);
err := encoder.Encode(data)
if err != nil {
fmt.Println("Unable to serialize data:", err)
return
}

decoder := gob.NewDecoder(buffer)
data = nil
err = decoder.Decode(&data)
if err != nil {
fmt.Println("Unable to deserialize data:", err)
}
fmt.Println("Data after:", data)
}

I add the bin path of the go tools from the go1beta2 appengine
distribution to my path and build and run a number of times:

FrancisMBA:server francisli$ 6g gob_test.go
FrancisMBA:server francisli$ 6l gob_test.6
FrancisMBA:server francisli$ ./6.out
Data before: map[foo:map[bar:baz] test:testing]
Unable to deserialize data: gob: name not registered for interface: "ar
\x06string\f\x05\x00\x03baz\x04test\x06string\f\t\x00\atesting
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
Data after: map[foo:map[]]
FrancisMBA:server francisli$ ./6.out
Data before: map[foo:map[bar:baz] test:testing]
Data after: map[foo:map[] test:testing]
FrancisMBA:server francisli$ ./6.out
Data before: map[foo:map[bar:baz] test:testing]
Data after: map[foo:map[] test:testing]
FrancisMBA:server francisli$ ./6.out
Data before: map[foo:map[bar:baz] test:testing]
Data after: map[test:testing foo:map[]]
FrancisMBA:server francisli$ ./6.out
Data before: map[foo:map[bar:baz] test:testing]
Unable to deserialize data: gob: name not registered for interface: "ar
\x06string\f\x05\x00\x03baz\x04test\x06string\f\t\x00\atesting
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
Data after: map[foo:map[]]
FrancisMBA:server francisli$

Before I file a bug with this, is there something I'm missing or doing
horribly wrong? I'm on Mac OS X 10.7.2, on a latest generation MacBook
Air (Core i5), running the go1beta2 tools from the darwin_amd64
distribution...

Francis


On Feb 14, 6:27 pm, David Symonds <dsymo...@golang.org> wrote:

David Symonds

unread,
Feb 14, 2012, 11:12:05 PM2/14/12
to Francis Li, google-appengine-go
On Wed, Feb 15, 2012 at 3:04 PM, Francis Li <fra...@tikitakistudio.com> wrote:

> gob.Register(make(map[string]interface{}))

You shouldn't need this.

But this may indeed be a bug in the gob package. File a bug at
http://code.google.com/p/go/issues/list with this reproduction case.


Dave.

Francis Li

unread,
Feb 15, 2012, 12:16:43 AM2/15/12
to google-appengine-go
On Feb 14, 8:12 pm, David Symonds <dsymo...@golang.org> wrote:
> On Wed, Feb 15, 2012 at 3:04 PM, Francis Li <fran...@tikitakistudio.com> wrote:
> > gob.Register(make(map[string]interface{}))
>
> You shouldn't need this.
>
> But this may indeed be a bug in the gob package. File a bug athttp://code.google.com/p/go/issues/listwith this reproduction case.
>
> Dave.

Done, moving this over to:

http://code.google.com/p/go/issues/detail?id=3026

Thanks for your advice...

Sincerely,
Francis

Reply all
Reply to author
Forward
0 new messages