Project

General

Profile

Actions

Bug #13851

closed

getting "can't modify string; temporarily locked" on non-frozen instances

Added by chucke (Tiago Cardoso) over 6 years ago. Updated almost 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:82533]

Description

I'm doing some nonblocking IO, and using a local string for buffering to avoid allocations. Roughly the following

class A

  def initialize
    @buffer = String.new("", encoding: Encoding::BINARY)
  end

  def read(io)
     io.read_nonblock(16_384, @buffer, exception: false)
     # do stuff...
     @buffer.clear
  end

It all goes smoothly, mostly... until I start getting arbitrary error when calling #read_nonblock. Here's an example backtrace:

DEBUG: can't modify string; temporarily locked- - - [30/Aug/2017:13:15:09 +0300] "GET / 1.0" 200 - 0.0000
DEBUG: <internal:prelude>:76:in `__read_nonblock'
DEBUG: <internal:prelude>:76:in `read_nonblock'
DEBUG: /Users/user/Projects/project:NN in `read``
....

I can't unfortunately reproduce this in a deterministic way. I can only say that the read routine is called in multiple threads (different io's instances of that class). The errors come seldom, however.

I'm running ruby 2.3.4, and the frozen string literal is activated for the file where the class is defined. I first assumed that it was the buffer, but due to its initialization, it should be marken as not-frozen.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0