ok, 1st guess is wrong.
do you run your code with race enabled ?

On Tuesday, March 28, 2017 at 4:08:17 PM UTC+3, Danilo Cianfrone wrote:
>
> Doesn't work, and doesn't make sense, even.
> I assume the problem is in the channel, but can't figure out which and why.
>
> Il giorno martedì 28 marzo 2017 14:47:40 UTC+2, dja...@gmail.com ha 
> scritto:
>>
>> >> go func(j tengin.Job) { m.OnJob(j); m.Done() }(job)
>> func(j tengin.Job) { go func(){ m.OnJob(j); m.Done()}() }(job)
>>
>> Djadala
>> On Tuesday, March 28, 2017 at 3:27:34 PM UTC+3, Danilo Cianfrone wrote:
>>>
>>> I'm experiencing a weird bug.
>>> I have a microservice that uses FBP architecture, with a structure 
>>> *graph* as main graph and *multiplexer* as first component.
>>>
>>> The code is the following:
>>>
>>> type graph struct {
>>> loggable
>>> fetchable
>>>
>>> multiplexer
>>> fetcher
>>> nodeEvaluator
>>> joiner
>>> treeEvaluator
>>>
>>> closed   atomic.Value
>>> listener atomic.Value
>>> }
>>>
>>> func (g *graph) Submit(job tengin.Job) error {
>>> if closed := g.closed.Load().(bool); closed {
>>> return ErrClosed
>>> }
>>>
>>> if err := job.Validate(); err != nil {
>>> return err
>>> }
>>>
>>> g.Logger.Debug("added new job to the input channel", job.ZapField())
>>>
>>> g.multiplexer.Add(1)
>>> g.multiplexer.Job <- job
>>> return nil
>>> }
>>>
>>> type multiplexer struct {
>>> sync.WaitGroup
>>> loggable
>>> multiplexerCallbacks
>>>
>>> Job        chan tengin.Job
>>> FetcherOut chan tengin.Job
>>> NodeOut    chan tengin.Job
>>> }
>>>
>>> func (m *multiplexer) Handler() {
>>> go func() {
>>> for job := range m.Job {
>>> m.Logger.Debug("JOB ARRIVED", job.ZapField())
>>> go func(j tengin.Job) { m.OnJob(j); m.Done() }(job)
>>> }
>>> }()
>>> }
>>>
>>> type Job struct {
>>> Event ResourceEvent `json:"event"`
>>> Stuff *stuff.Stuff  `json:"stuff"`
>>> }
>>>
>>> Every Job is submitted in the main graph, and the *graph.Submit()* function 
>>> writes the incoming Job into the multiplexer Job channel.
>>> The *multiplexer.Handler() *listens for incoming jobs from the Job 
>>> channel, and executes the *multiplexer.OnJob() *function *(which is 
>>> basically state-less).*
>>>
>>> Let's say I'm feeding two Jobs to the graph, *Job1 *and *Job2*, where 
>>> *Job1.Stuff.ID 
>>> <http://Job1.Stuff.ID> = x *and *Job2.Stuff.ID <http://Job2.Stuff.ID> = 
>>> y*
>>> The *multiplexer.Handler() *receives 2 Jobs, but they're *2 instances 
>>> of Job2!*
>>>
>>> In fact, the Logger on *Submit()* prints Job1 and Job2 as one would 
>>> expect, but the Logger on *Handler() *prints *2 times Job2!*
>>> Maybe I'm missing something, but *go vet* doesn't highlight any 
>>> problems.
>>>
>>>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to