I've spent a couple of days trying to solve a problem. Now that I've solved
it, I'm wondering if anyone here might be able to explain what was wrong.

Short version:

- b := bytes.Buffer{}- decoder := gob.NewDecoder(&b) for {

- b.Reset()

+ var b bytes.Buffer+ decoder := gob.NewDecoder(&b)

The old version, declaring the buffer and decoder outside the loop,
actually worked fine -- I was able to bring up dozens of peers and
they were able to communicate.

The problem occurred when I added additional servers to the cluster
after the others had already been communicating. Then I'd get "gob:
unknown type id or corrupted data" for every message the newly-added
servers received (the "old" servers had no errors). Declaring the
buffer and decoder inside the loop solves the problem.

More details:

    - This is a clustered chat server
    - The problem occurred even with a very simple gob (a struct
containing only one string)
    - The problem occurred both in Docker containers and Digital Ocean
droplets, so I don't think it's a networking issue
    - I'm using Go 1.6.2 on 64-bit Ubuntu
    - I made a simplified version of my code and was able to replicate
the problem
    - Servers are communicating with one another using the gorilla
websocket library
    - The problem happens regardless of whether or not the servers all
start at once -- the trigger is if "new" server A connects to existing
server B, and server B has already been communicating with other
servers, then server A gets "corrupted" messages -- despite the fact
that literally the same bytes are being sent by server B to the other
servers server B has been talking to and they're fine
    - Checking the length of the buffer on the sender and the length of
the raw bytes from the receiver shows that the size matches at both

Thanks for looking! I'd really like to understand what was going on --
especially if the "fix" could be a performance issue.

You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 6 | next ›
Discussion Overview
groupgolang-nuts @
postedJun 1, '16 at 6:36p
activeJun 1, '16 at 7:47p

3 users in discussion

Shawn Milochik: 3 posts Egon: 2 posts Voidlogic: 1 post



site design / logo © 2021 Grokbase