ruby / csv

CSV Reading and Writing
https://ruby.github.io/csv/
BSD 2-Clause "Simplified" License
181 stars 114 forks source link

A fiber to execute ':heder_converters' has been changed since v3.2.6 #285

Closed niku closed 1 year ago

niku commented 1 year ago

I run into an unexpected behavior when I use fiber local variable in heder_converters block. To reproduce following:

~/csv (tags/v3.2.6)
git checkout v3.2.5
HEAD is now at 502197b Add 3.2.5 entry
~/csv (tags/v3.2.5)
bundle exec ruby -r csv -e 'p CSV::VERSION; main_fiber = Fiber.current; Thread.current[:a]="a"; CSV.new("id,name,age\n1,2,3\n", headers: true, header_converters: ->(h) { p [Fiber.current == main_fiber, Thread.current[:a]] }).to_a;'
"3.2.5"
[true, "a"]
[true, "a"]
[true, "a"]
~/csv (tags/v3.2.5)
git checkout v3.2.6
Previous HEAD position was 502197b Add 3.2.5 entry
HEAD is now at 816b48b Add 3.2.6 entry
~/csv (tags/v3.2.6)
bundle exec ruby -r csv -e 'p CSV::VERSION; main_fiber = Fiber.current; Thread.current[:a]="a"; CSV.new("id,name,age\n1,2,3\n", headers: true, header_converters: ->(h) { p [Fiber.current == main_fiber, Thread.current[:a]] }).to_a;'
"3.2.6"
[false, nil]
[false, nil]
[false, nil]

I suppose it may not a bug. If so, feel free to close it. Thanks.

kou commented 1 year ago

I think that acc05116c55579b78925dd27024969b9daf69135 is related.

It seems that Enumerator#each uses the same fiber but Enumerator#next uses a different fiber.