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

Is Select() providing the same value twice or am i missing something here? #16

Open
edhemphill opened this issue Jan 29, 2024 · 3 comments

Comments

@edhemphill
Copy link

edhemphill commented Jan 29, 2024

Had a section of code which pulls a value from a zenq queue:

		if dat := zenq.Select(b.notifyQ, b.writeQ); dat != nil {
			switch dat.(type) {
			case *bounceNofity:
				switch dat.(*bounceNofity).event {
				case bShutdown:
					model_debugf("BounceMap: writerLoop got shutdown")
					shutdown = true
				case bShutdownnow:
					break writerLoop
				}
			case *Bounce:
				bnc := dat.(*Bounce)
				if bnc.writecb != nil {
					bnc.writecb(bnc)
				}
				if bnc.writecb2 != nil {
					bnc.writecb2(bnc)
				}
			}

When doing a tests of a 1000 concurrent "Bounce" pointers coming in to the zenq concurrently, i get a handful of duplicate reads from zenq.

When i switch the zenq over to a normal channel, I don't have this issue:

		select {
		case bnc := <-b.writeQ:
			if bnc.writecb != nil {
				bnc.writecb(bnc)
			}
			if bnc.writecb2 != nil {
				bnc.writecb2(bnc)
			}
		case ev := <-b.notifyQ:
			switch ev.event {
			case bShutdown:
				model_debugf("BounceMap: writerLoop got shutdown")
				shutdown = true
			case bShutdownnow:
				break writerLoop
			}
		}

Provided 4 sources files to completely reproduce the test in question: TestBounceMap1000

I may well have a bug in my code. Or just don't understand something fundamental about Zenq - but by switching out to channels i dont have the issue.

go test -tags model_debug -v -run TestBounceMap
@edhemphill
Copy link
Author

edhemphill commented Jan 29, 2024

test.zip

In the code, the chan version is currently on, and the zenq version is commented out.

@edhemphill
Copy link
Author

Also, on aarch64 machine - MacOS M1 Max

@alphadose
Copy link
Owner

I will check this out and get back to you

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

No branches or pull requests

2 participants