What Could Be Causing This Rails Ioerror Closed Stream

what could be causing this rails ioerror closed stream?

I think I've figured it out, at least I think I do ( the client just keeps on uploading now, error-free ) .
After you read data from a file that you upload, you should also CLOSE it. Who would have thought? :P

IOError (closed stream) on ActiveStorage::Attached::One#attach (Rails 6)

Okay, I found the answer. In rails 6 you have to open the tempfile again, when attaching, like this:

io: File.open(tempfile.path),

Hope this helps anyone with the same issue.

Capybara Poltergeist IOError: closed stream

The solution that worked best was to initiate a new Capybara session like this:

session = Capybara::Session.new(:poltergeist, Rails.application)
session.visit(...)
session.driver.quit

For my program I encapsulated it in a WebScraper module like this:

module WebScraper
attr_accessor :session

delegate :visit, :save_screenshot, to: :session

def start_session
@session ||= Capybara::Session.new(:poltergeist, Rails.application)
end

def end_session
@session.driver.quit
@session = nil
end
end

Uploading files to S3 using paperclip, IOError (closed stream) error

It looks like this is caused by a race condition between the ruby garbage collector and Tempfile.

Someone developed a patch for rails projects here: https://github.com/jwinky/ruby_tempfile_ioerror

Ruby gets stream closed stream IO error

I am on a different system so I cannot check your code. Anyway I suggest using File.foreach:

File.foreach("packages_list.txt") do |line|
package_id = line.split[0].to_i
package = line.split[1]
dependencies = ""
url = BASE_URL + package
if package_id >= last_package
doc = Nokogiri::HTML(open(url))
doc.css(".uldep a").each do |dependency|
dependencies << dependency.text + ","
end
dependencies = dependencies.split(',').uniq.join(',')
description = doc.css('#pdesc').text.strip
if doc.css('#content h1').text
version = doc.css('#content h1').text.strip.scan( /\(([^>]*)\)/).last.first
end

File.open("packages/#{package}","w") do |wfptr|
wfptr.puts "PackageId:#{package_id}"
wfptr.puts "Name:#{package}"
wfptr.puts "Deps:#{dependencies}"
end
File.open("packages/#{package}.description",'w') {|wf| wf.write(description.capitalize)}

package_id += 1
puts "Now Processing #{package_id}"
File.open('lastbreak','w') { |fptr| fptr.puts "#{package_id}" }
end
end


Related Topics



Leave a reply



Submit