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

Fixes intermittent ConcurrencyError seen in JRuby #670

Merged
merged 1 commit into from
Apr 25, 2014
Merged

Fixes intermittent ConcurrencyError seen in JRuby #670

merged 1 commit into from
Apr 25, 2014

Conversation

cbusbey
Copy link
Contributor

@cbusbey cbusbey commented Apr 22, 2014

This fixes a ConcurrencyError seen intermittently in JRuby 1.7.4 where a separate native thread was writing to stdout. This error was observed in v1.3.8.

Detected invalid array contents due to unsynchronized modifications with concurrent users (ConcurrencyError)
org/jruby/RubyArray.java:1153:in <<' /home/jenkins/.rvm/gems/jruby-1.7.4/gems/cucumber1.3.8/bin/../lib/cucumber/formatter/interceptor.rb:14:inwrite'
org/jruby/RubyIO.java:2350:in write' org/jruby/RubyIO.java:2305:inputs'
org/jruby/RubyKernel.java:577

This may be an issue for other non-MRI versions of ruby as well.

@os97673
Copy link
Member

os97673 commented Apr 23, 2014

I wonder what is the contract for IO operations in ruby? I had an impression that they are supposed to be thread-safe. Am I wrong?
If not then it is a bug in JRuby not in Cucumber. If I'm wrong could you please point me the doc/blog post which states this (perhaps there are some other common constructions which are not thread-safe too and we do you them)

@cbusbey
Copy link
Contributor Author

cbusbey commented Apr 23, 2014

Not sure on the IO contract (maybe someone lurking from @jruby can chime in here). But I do know that the Array type used by buffer is definitely not thread safe.

https://github.com/jruby/jruby/wiki/Concurrency-in-jruby#core-classes-and-standard-library

Hence the concurrency error when multiple threads attempt to write to and read from the interceptor buffer.

end

def buffer
lock.synchronize do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to return the buffer itself not its copy. Are you sure it is safe to return a copy here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, its really just another thread safety precaution to protect buffer from being accessed/written to from separate threads. As far as I can tell, It looks like buffer is currently only being used by the junit formatter in after_feature here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for clarification.

os97673 added a commit that referenced this pull request Apr 25, 2014
Fixes intermittent ConcurrencyError seen in JRuby
@os97673 os97673 merged commit 9c926b0 into cucumber:v1.3.x-bugfix Apr 25, 2014
@os97673
Copy link
Member

os97673 commented Apr 25, 2014

I'm on RailsConf now so will not be able to release a new version until next week.

os97673 pushed a commit that referenced this pull request May 9, 2014
@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants