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

encoding/gob: not decodable from another instance of same program #24126

Closed
pjebs opened this issue Feb 26, 2018 · 6 comments
Closed

encoding/gob: not decodable from another instance of same program #24126

pjebs opened this issue Feb 26, 2018 · 6 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@pjebs
Copy link
Contributor

pjebs commented Feb 26, 2018

I have the same program running on 2 different nodes (kubernetes scaling).

I called gob Register and then Encode the interface{} struct and store the value in a common redis instance.

This works as intended and perfectly if the Decode occurs from the same instance that encoded it.

If the decode occurs from the other instance it fails.

I suspect the Register function is the culprit when dealing with encoding interfaces.

Is this a bug. If not, this greatly detracts from the portability of the gob package.

@pjebs
Copy link
Contributor Author

pjebs commented Feb 26, 2018

@andizzle

@cznic
Copy link
Contributor

cznic commented Feb 26, 2018

Please add a minimal self-contained reproducer.

Side note: registering interface type assigns a number -> type mapping. The decoding process must register the same types in the same order otherwise the type numbers do not match. Is you program written in such a way that the type-registering order is deterministic and repeatable? I've had a similar problem in cznic/ql#67.

@pjebs
Copy link
Contributor Author

pjebs commented Feb 26, 2018

I just use plain Register

@cznic
Copy link
Contributor

cznic commented Feb 26, 2018

That's the only option ;-) But the interesting information is if the're only a single call to Register in the whole program, or if there are more of them. In the later case, it's important to guarantee, that they always occur in the exact same order. Note that any package you import may also call Register. As long as the encoding and decoding programs are identical and the calls to Register occur only in init() functions, this should be guaranteed. Is that the case in you failing program?

@bradfitz bradfitz added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 26, 2018
@bradfitz bradfitz changed the title gob not decodable from another instance of same program encoding/gob: not decodable from another instance of same program Feb 26, 2018
@bradfitz bradfitz added this to the Unplanned milestone Feb 26, 2018
@andizzle
Copy link

@pjebs, @cznic could be right, we are not using init() to Register. The Register can occur multiple times in dynamic order in the current program. Let's investigate.

@pjebs
Copy link
Contributor Author

pjebs commented Feb 26, 2018

Closing. Gob is working as intended.
Our situation was caused because the second instance, after decoding the encoded gob in redis, didn't have the struct registered.

We were doing something along the lines of this: https://github.com/pjebs/GAE-Toolkit-Go/blob/master/cache/cache.go#L84
This meant the second instance didn't have the struct registered, so would call the operation manually again - but after that it will register the struct - so it would it be good from then onwards.

@pjebs pjebs closed this as completed Feb 26, 2018
@golang golang locked and limited conversation to collaborators Feb 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants