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

Channel.Write after Channel.Close #29

Open
Adirio opened this issue May 3, 2018 · 1 comment · May be fixed by #30
Open

Channel.Write after Channel.Close #29

Adirio opened this issue May 3, 2018 · 1 comment · May be fixed by #30

Comments

@Adirio
Copy link

Adirio commented May 3, 2018

When calling a Channel sink's Write method after having called its Close method, the select behaviour is non-deterministic, and may result in a valid Write call when it should return ErrSinkClosed.

Example:

chSink := NewChannel(10)
ch := chSink.C
queue := NewQueue(chSink)

for i := 0; i < 50; i++ {
	queue.Write(i)
}

time.Sleep(time.Millisecond)
// 10 elements in then chan, 1 blocked and 39 in the queue events list

chSink.Close()

outer:
for {
	select {
	case i := <-ch:
		fmt.Println(i)
	case <-time.After(time.Second):
		break outer // end the infinite loop whenh there is nothing more to print
	}
}

Output:

0
1
2
3
4
5
6
7
8
9
11
12
16
18
19
22
27
28
35
37
40
42
43
44
45

Expected output:
It should only print 0-9.
10 is kind of undefined as its Write function was called before the Close but it got stuck there, so either printing or droping it would be ok.
11-49 should not be printed in any way as their Write method is not called until 10's call finishes and Close is being called before that.

@Adirio
Copy link
Author

Adirio commented May 3, 2018

The tests are not picking this error because they use a 0 buffer, setting it to any other number will make the test fail.

Adirio pushed a commit to Adirio/go-events that referenced this issue May 3, 2018
Signed-off-by: Adrián Orive <aorive@ikerlan.es>
Adirio pushed a commit to Adirio/go-events that referenced this issue May 3, 2018
Signed-off-by: Adrián Orive <aorive@ikerlan.es>
@Adirio Adirio linked a pull request May 3, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant