blob: 860167e12cd51efb6783478d95c38d9f88f5c49b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# frozen_string_literal: true
if RUBY_PLATFORM.include?('darwin')
require 'fiddle'
require 'ffi'
module CFTimeZone
extend FFI::Library
ffi_lib '/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation'
attach_function :CFTimeZoneCopyDefault, [], :pointer
attach_function :CFTimeZoneGetName, [:pointer], :pointer
attach_function :CFRelease, [:pointer], :void
end
# Dynamically load Foundation.framework, ~implicitly~ initialising
# the Objective-C runtime before any forking happens in webserver
#
# From https://bugs.ruby-lang.org/issues/14009
Fiddle.dlopen '/System/Library/Frameworks/Foundation.framework/Foundation'
# grpc uses abseil-cpp to retrieve the local time zone via macOS APIs:
# https://github.com/abseil/abseil-cpp/blob/20230125.rc3/absl/time/internal/cctz/src/time_zone_lookup.cc#L139
#
# To ensure these APIs are not called in a forked process (https://github.com/grpc/grpc/issues/26257),
# load the required framework, retrieve the default time zone, and then release the resource.
default_time_zone = CFTimeZone.CFTimeZoneCopyDefault
time_zone_name = CFTimeZone.CFTimeZoneGetName(default_time_zone)
CFTimeZone.CFRelease(time_zone_name)
CFTimeZone.CFRelease(default_time_zone)
end
|