You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue
Opening a TCPSocket and using the send method, freezes the string being sent on JRuby 9000.
This is unexpected and isn't experienced in MRI.
This issue doesn't occur when using socket.write (blocks until done, inherited from the IO class).
How to replicate
Open a TCPSocket object.
Create a long string (so string is a pointer).
Send string using socket.send data, 0
Try to modify string.
Example code
It's possible to replicate the error using the following code:
require'socket'Thread.newdobeginserver=TCPServer.new3000whilesock=server.acceptsleep10sock.closeendrescue=>eserver.closeendendlong_string="JRuby is an implementation of the Ruby language using the JVM.It aims to be a complete, correct and fast implementation of Ruby, at the same time as providing powerful new features such as concurrency without a global-interpreter-lock, true parallelism, and tight integration to the Java language to allow you to uses Java classes in your Ruby program and to allow JRuby to be embedded into a Java application.You can use JRuby simply as a faster version of Ruby, you can use it to run Ruby on the JVM and access powerful JVM libraries such as highly tuned concurrency primitives, you can use it to embed Ruby as a scripting language in your Java program, or many other possibilites."20.timesdo |i|
begins=TCPSocket.new'localhost',3000str=long_string.dups.sendstr,0str.clear# => JRUBY: RuntimeError: can't modify frozen string# => MRI: ""rescue=>eputs"Test \##{i} raised an exception: #{e.message}"ensures.closeendend
The text was updated successfully, but these errors were encountered:
boazsegev
changed the title
Socket.send freezes string unexpectedly (RuntimeError: can't modify frozen string)
Socket.send SOMETIMES freezes string unexpectedly (RuntimeError: can't modify frozen string)
Aug 13, 2015
boazsegev
changed the title
Socket.send SOMETIMES freezes string unexpectedly (RuntimeError: can't modify frozen string)
Socket.send freezes string unexpectedly (RuntimeError: can't modify frozen string)
Aug 13, 2015
Do you think it would be better to move the Dup+freeze to the write_nonblock?
It seems to me that since syswrite is a blocking method, then data integrity should be assumed and no duplication nor freezing should be required (unless the string is modified, which doesn't seem to be the case).
On the other hand, the write_nonblock should probably Dup+freeze before returning, to maintain data integrity.
This is a micro-optomization that might create data integrity risks if the string is accessed by more than one thread - but these are integrity issues that should probably be handled by the multi-threaded code rather than by JRuby. In fact, I believe that having JRuby protect data integrity on a blocking method will probably result in double the protection when multi-threading is an issue.
The issue
Opening a TCPSocket and using the
send
method, freezes the string being sent on JRuby 9000.This is unexpected and isn't experienced in MRI.
This issue doesn't occur when using
socket.write
(blocks until done, inherited from the IO class).How to replicate
socket.send data, 0
Example code
It's possible to replicate the error using the following code:
The text was updated successfully, but these errors were encountered: