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

WIP: Use POSIX::Spawn::Child instead of #popen3 to avoid deadlocks #738

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions lib/wicked_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
require 'digest/md5'
require 'rbconfig'

if (RbConfig::CONFIG['target_os'] =~ /mswin|mingw/) && (RUBY_VERSION < '1.9')
require 'win32/open3'
if ENV['WICKED_POPEN'] == 'ruby'
if (RbConfig::CONFIG['target_os'] =~ /mswin|mingw/) && (RUBY_VERSION < '1.9')
require 'win32/open3'
else
require 'open3'
end
else
require 'open3'
require 'posix/spawn'
end

begin
Expand Down Expand Up @@ -75,8 +79,13 @@ def pdf_from_url(url, options = {})

print_command(command.inspect) if in_development_mode?

err = Open3.popen3(*command) do |_stdin, _stdout, stderr|
stderr.read
err = if ENV['WICKED_POPEN'] == 'ruby'
Open3.popen3(*command) do |_stdin, _stdout, stderr|
stderr.read
end
else
child = POSIX::Spawn::Child.new(*command)
child.err
end
if options[:return_file]
return_file = options.delete(:return_file)
Expand Down Expand Up @@ -110,7 +119,20 @@ def print_command(cmd)
end

def retrieve_binary_version
_stdin, stdout, _stderr = Open3.popen3(@exe_path + ' -V')
command = [
@exe_path,
'-V'
]

stdout = if ENV['WICKED_POPEN'] == 'ruby'
Open3.popen3(*command) do |_stdin, stdout, _stderr|
stdout.read
end
else
child = POSIX::Spawn::Child.new(*command)
child.out
end

@binary_version = parse_version(stdout.gets(nil))
rescue StandardError
DEFAULT_BINARY_VERSION
Expand Down
1 change: 1 addition & 0 deletions wicked_pdf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ DESC
spec.requirements << 'wkhtmltopdf'

spec.add_dependency 'activesupport'
spec.add_dependency 'posix-spawn', '~> 0.3.11'

spec.add_development_dependency 'rails'
spec.add_development_dependency 'bundler', '~> 1.3'
Expand Down