Skip to content

Pipe with SharedBuffer channels will be dead lock #28

@homerzhou

Description

@homerzhou

Fllow is the example code, the example code is from eapache/channels readme.

// never more than 3 elements in the pipeline at once
buf := NewSharedBuffer(3)

ch1 := buf.NewChannel()
ch2 := buf.NewChannel()

// or, instead of a straight pipe, implement your pipeline step
Pipe(ch1, ch2)

// inputs
go func() {
	for i := 0; i < 20; i++ {
		ch1.In() <- i
	}
	ch1.Close()
}()

time.Sleep(10 * time.Second)

for _ = range ch2.Out() {
	// outputs
}

buf.Close()

the flow graph is blow
data => ch1-in => ch1-out => ch2-in => ch2-out => data

Fllow scenario will deadlock

  1. ch1's length is 3, ch2's length is 0, all recv blocked
  2. ch1-out read one data, before send to ch2-in
  3. ch1's length is 2, ch2's length is 0, all recv unblocked
  4. ch1-in have another data in
  5. ch1's length is 3, ch2's length is 0, all recv blocked
  6. than the second data can not insert into ch2-in, event ch2-out is always ready

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions