Skip to content

thread.object_id with fibers (due AR's connection pooling) #1717

Description

@kares

MRI (in 2.x) does return the same object_id for Thread.current inside a Fiber ... this is not how JRuby behaves (even on master). it's quite important esp. due the fact that Rails uses Thread.current.object_id as it's key to store/resolve DB connections thread-locally using a pool ... they seem to not be doing anything about it - thus decided to re-report the issue here rails/rails#7746

Rails might switch to using thread_variable_xxx but this is also not currently available on JRuby (2.x mode) - which might be another approach to handle this right for structures such as thread mapped connection pools. MRI 2.1 samples :

Thread.new {
  Thread.current[:foo] = "bar"
  p [Thread.current.object_id, Thread.current[:foo]]

  Fiber.new {
    p [Thread.current.object_id, Thread.current[:foo]]
  }.resume
}.join
[23336800, "bar"]
[23336800, nil]
Thread.new {
  Thread.current.thread_variable_set :foo, "bar"
  p [Thread.current.object_id, Thread.current.thread_variable_get(:foo)]

  Fiber.new {
    p [Thread.current.object_id, Thread.current.thread_variable_get(:foo)]
  }.resume
}.join
[23281980, "bar"]
[23281980, "bar"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions