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

FiberError/NoMemoryError error related to csv gem occurs when upgrading from ruby ​​3.1 to 3.3 #326

Open
nguyenvd27 opened this issue Dec 23, 2024 · 8 comments

Comments

@nguyenvd27
Copy link

When upgrading from ruby 3.1.4 to 3.3.5, FiberError/NoMemoryError error related to csv occurred in our system. In addition, when loading csv file, CPU load also increases compared to before.

  • FiberError: can't alloc machine stack to fiber (1 x 659456 bytes): Cannot allocate memory error
  • NoMemoryError: failed to allocate memory

After investigation we found the cause. It was caused by csv gem. When upgrading ruby ​​version, csv version is also updated (from 3.2.5 to 3.2.8)
Even if we try to keep ruby ​​3.1.4 and only update csv gem to 3.2.8, the FiberError/NoMemoryError error will still occur
We have upgraded ruby ​​3.3.5 and kept the csv gem version 3.2.5 (same as ruby ​​version 3.1.4) and FiberError/NoMemoryError didn't occur and CPU load also didn't increase

It seems that some changes from csv 3.2.5 to 3.2.8 caused the error. This commit of csv gem is very suspicious

@kou
Copy link
Member

kou commented Dec 23, 2024

Could you provide a script that reproduces this?

@nguyenvd27
Copy link
Author

@kou
The code in my application like this

catch(:max_lines) do
  File.open(file.path, "rt").each_line.with_index do |line, i|
    # handle line with gsub...
    csv_parse = CSV.parse(line.gsub(/\r\n?/, "\n"))
    # ...
    csv_parse.each do |row|
      # ...
      @file_content << row
    end
  end
end

In csv 3.2.8, FiberError/NoMemoryError will occur if we upload large csv file multiple times
In csv 3.2.5, No problem if we upload large csv file multiple times

@kou
Copy link
Member

kou commented Dec 23, 2024

Thanks.
Could you also provide sample data that reproduce this problem? (You don't need to use a real data. I just want to reproduce this on local.)

@kou
Copy link
Member

kou commented Dec 23, 2024

BTW, CSV.parse(...) do |row| will be better than csv_parse = CSV.parse(...); csv_parse.each do |row|.

@nguyenvd27
Copy link
Author

nguyenvd27 commented Dec 23, 2024

We only use csv files with normal data with 10000 lines, sample data
Screenshot 2024-12-23 at 16 15 31
or
Screenshot 2024-12-23 at 16 22 30

I just want to reproduce this on local

Because the local memory is so large, we cannot reproduce it on local but can only reproduce it on the test environment (stagging, RAM: 9.6GB)

@kou
Copy link
Member

kou commented Dec 23, 2024

Hmm. I can't debug this without reproducible data...

@kou
Copy link
Member

kou commented Dec 23, 2024

Can you provide compose.yaml (for docker compose) that can limit available memory?

@nguyenvd27
Copy link
Author

ohhh sorry. We are using Jenkins and don't have docker compose for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants