ZenQ icon indicating copy to clipboard operation
ZenQ copied to clipboard

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

Open edhemphill opened this issue 1 year ago • 3 comments

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 avatar Jan 29 '24 01:01 edhemphill

test.zip

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

edhemphill avatar Jan 29 '24 01:01 edhemphill

Also, on aarch64 machine - MacOS M1 Max

edhemphill avatar Jan 29 '24 01:01 edhemphill

I will check this out and get back to you

alphadose avatar Jan 29 '24 03:01 alphadose