Skip to content

Commit

Permalink
Merge pull request #387 from fluent/replace-openssl-in-rubyinstaller
Browse files Browse the repository at this point in the history
msi: Replace OpenSSL with MinGW's latest one to fix memory leak
  • Loading branch information
ashie authored May 10, 2022
2 parents a7f5713 + 4712eb0 commit 91955c5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
56 changes: 45 additions & 11 deletions td-agent/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class DownloadTask
attr_reader :file_ruby_source, :file_ruby3_source, :file_ruby_installer_x64
attr_reader :file_fluentd_archive
attr_reader :files_ruby_gems
attr_reader :file_openssl_source
attr_reader :file_openssl_source, :file_mingw_openssl

def initialize(logger:)
@logger = logger || Logger.new(STDOUT, level: Logger::Severity::INFO)
Expand All @@ -202,6 +202,7 @@ class DownloadTask
[
@file_jemalloc_source,
@file_openssl_source,
@file_mingw_openssl,
@file_ruby_source,
@file_ruby3_source,
@file_ruby_installer_x64,
Expand All @@ -216,6 +217,7 @@ class DownloadTask
define_fluentd_archive
define_gem_files
define_openssl_file
define_mingw_openssl_file

namespace :download do
desc "Download jemalloc source"
Expand All @@ -232,6 +234,9 @@ class DownloadTask

desc "Download openssl source"
task :openssl => @file_openssl_source

desc "Download MinGW's openssl package"
task :mingw_openssl => @file_mingw_openssl
end
end

Expand Down Expand Up @@ -326,6 +331,20 @@ class DownloadTask
end
end

def define_mingw_openssl_file
version = MINGW_OPENSSL_VERSION
sha256sum = MINGW_OPENSSL_SHA256SUM
filename = "mingw-w64-x86_64-openssl-#{version}-any.pkg.tar.zst"
url_base = "https://mirror.msys2.org/mingw/mingw64/"
url = "#{url_base}#{filename}"

@file_mingw_openssl = File.join(DOWNLOADS_DIR, filename)

file @file_mingw_openssl do
download_file(url, filename, sha256sum)
end
end

def define_fluentd_archive
@file_fluentd_archive = File.join(DOWNLOADS_DIR, "fluentd-#{FLUENTD_REVISION}.tar.gz")
file @file_fluentd_archive do
Expand Down Expand Up @@ -407,7 +426,7 @@ class BuildTask
namespace :build do
desc "Install jemalloc"
task :jemalloc => [:"download:jemalloc"] do
build_jemalloc unless windows?
build_jemalloc
end

desc "Install OpenSSL"
Expand All @@ -420,14 +439,16 @@ class BuildTask

desc "Install Ruby"
task :ruby => [:jemalloc, :openssl, :"download:ruby"] do
if windows?
extract_ruby_installer
apply_ruby_installer_patches
setup_windows_build_env
find_and_put_dynamiclibs
else
build_ruby_from_source
end
build_ruby_from_source
end

desc "Install Ruby for Windows"
task :rubyinstaller => [:"download:ruby", :"download:mingw_openssl"] do
extract_ruby_installer
apply_ruby_installer_patches
replace_openssl_in_ruby_installer
setup_windows_build_env
find_and_put_dynamiclibs
end

desc "Install ruby gems"
Expand All @@ -448,7 +469,7 @@ class BuildTask
end

desc "Install fluentd"
task :fluentd => [:"download:fluentd", :ruby] do
task :fluentd => [:"download:fluentd", windows? ? :rubyinstaller : :ruby] do
cd(DOWNLOADS_DIR) do
archive_path = @download_task.file_fluentd_archive
fluentd_dir = archive_path.sub(/\.tar\.gz$/, '')
Expand Down Expand Up @@ -826,6 +847,19 @@ class BuildTask
end
end

# Fix memory leak in OpenSSL: https://github.com/fluent/fluent-package-builder/issues/374
def replace_openssl_in_ruby_installer
tarball = @download_task.file_mingw_openssl
sh(*tar_command, "xvf", tarball, "-C", DOWNLOADS_DIR, "--force-local")
source_dir = File.join(DOWNLOADS_DIR, "mingw64", "bin")
ensure_directory(td_agent_staging_dir) do
dest_dir = File.join(".", "bin", "ruby_builtin_dlls")
cp(File.join(source_dir, "libcrypto-1_1-x64.dll"), dest_dir)
cp(File.join(source_dir, "libssl-1_1-x64.dll"), dest_dir)
end
rm_rf(source_dir)
end

def find_and_put_dynamiclibs
begin
require 'ruby_installer/runtime'
Expand Down
4 changes: 4 additions & 0 deletions td-agent/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# https://www.openssl.org/source/
OPENSSL_VERSION = "1.1.1n"

# To fix memory leak issue: https://github.com/fluent/fluent-package-builder/issues/374
MINGW_OPENSSL_VERSION = "1.1.1.o-2"
MINGW_OPENSSL_SHA256SUM = "e1e642d441de3d6b9d4e499b42bb5464458e3a2d2431012b28e6f1ad94099167"

BUNDLER_VERSION= "2.3.11"

# https://www.ruby-lang.org/en/downloads/ (tar.gz)
Expand Down

0 comments on commit 91955c5

Please sign in to comment.