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

Concurrent 1 writer and 1 reader causes ets_buffer:read return {missing_ets_data, buffer_name, N} #32

Open
vjache opened this issue Jul 4, 2014 · 1 comment

Comments

@vjache
Copy link

vjache commented Jul 4, 2014

Hi,
I've simulated producer consumer schema with ets_buffer of type 'ring'.

  1. 1 writer process which in a loop (without explicit sleep) calls ets_buffer:write
  2. 1 reader process which in a loop (without explicit sleep and also with sleep 5 mls)
  3. size of a ring buffer is 200

Is it a situation (returning {missing_ets_data, buffer_name, -N}) which reader should tolerate in some way? If such, then which way is a most correct? Experimentally I've discovered that if I proceed with readings further then after some number of attempts (approx N times) I'll start to receive normal data.
Or it is still a some kind of a concurrency bug, and if such situation occur the ring buffer must be considered as 'broken' and should not be used any more by program? The documentation for 'missing_ets_data' is not clear for me.

@jaynel
Copy link
Member

jaynel commented Jul 5, 2014

This return value comes if the writer has allocated a place to write, but has not yet written to the slot. The reader retries 3 times with a yield() to give a chance for the writer to finish. This error should not happen, but it is harmless to ignore it and try the read again. The error indicates that the reader is faster than the writer.

Can you post your code so I can see what might be happening?

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