Test passes with `testrb`, but crashes using Rails `rake test`? - rake

I have a simple test to check that a carrierwave uploader works.
I use minitest for this, and the test works when run on its own, but not under Rails’s rake test... environment.
(Code for the test is included below.)
Things that work:
If I run ruby test/uploaders/image_file_uploader_test.rb the test passes.
If I run testrb test/uploaders/image_file_uploader_test.rb the test passes.
If I manually call all the lines in the test from IRB (not the Rails console), the code does what’s expected
If I create a small Rake TestTask to run the file (task also copied below), the test passes.
Things that do not work:
If I call rake test test/uploaders/image_file_uploader_test.rb I get dropped into the debugger (stack trace below)
If I call zeus rake test test/uploaders/image_file_uploader_test.rb I also get dropped into the debugger
What is strange:
If I head up the call stack in the debugger to the line in the test which has caused the failure – uploader.store!(#file) – and call it directly with (rdb:1) p uploader.store!(#file), it works! By which I mean, the method returns as expected and the file appears in the correct directory.
Thoughts?
I may be doing something really dumb here. It must be something to do with the Rake task loading the Rails environment, right? Am I doubly-including things or something? Is it something to do with the initializer in the Rails environment? (N.B., when I execute store! from the debugger, it stores the file in the location specified in the test, so it is overridding the Rails initializer successfully).
The backtraces
From bundle exec rake test test/uploaders/*_test.rb
# Running tests:
/Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/carrierwave-0.9.0/lib/carrierwave/uploader/store.rb:75: `' (NilClass)
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:926:in `_run_suite'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/parallel_each.rb:71:in `block in _run_suites'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/parallel_each.rb:71:in `map'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/parallel_each.rb:71:in `_run_suites'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:877:in `_run_anything'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1085:in `run_tests'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1072:in `block in _run'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1071:in `each'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1071:in `_run'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1059:in `run'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:795:in `block in autorun'
/Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/carrierwave-0.9.0/lib/carrierwave/uploader/store.rb:75:
(rdb:1) where
--> #1 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/carrierwave-0.9.0/lib/carrierwave/uploader/store.rb:75:in `rmdir'
#2 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/carrierwave-0.9.0/lib/carrierwave/uploader/store.rb:61:in `with_callbacks'
#3 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/carrierwave-0.9.0/lib/carrierwave/uploader/store.rb:58:in `store!'
#4 /Users/leo/Projects/PortfolioSite/test/uploaders/image_file_uploader_test.rb:38:in `test_upload_of_file'
#5 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1258:in `run'
#6 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:933:in `_run_suite'
#7 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/parallel_each.rb:71:in `_run_suites'
#8 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:877:in `_run_anything'
#9 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1085:in `run_tests'
#10 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1072:in `_run'
#11 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1059:in `run'
(rdb:1) up 3
#4 /Users/leo/Projects/PortfolioSite/test/uploaders/image_file_uploader_test.rb:38:in `test_upload_of_file'
(rdb:1) list
[33, 42] in /Users/leo/Projects/PortfolioSite/test/uploaders/image_file_uploader_test.rb
33 end
34
35 # The whole point of this is to upload a file.
36 def test_upload_of_file
37 uploader = ImageFileUploader.new
=> 38 uploader.store!(#file)
39 # Ensure the uploaded file is correct.
40 assert_equal Digest::SHA2.file(#file).hexdigest, Digest::SHA2.file("#{STORE_PATH}/#{FILENAME}").hexdigest
41 end
42
(rdb:1) p uploader.store!(#file)
[:store_versions!]
(rdb:1)
After the call to p uploader.store!(#file), the file has been saved
From zeus test test/uploaders/image_file_uploader_test.rb (this is pretty similar to the above)
/Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/carrierwave-0.9.0/lib/carrierwave/uploader/store.rb:75: `' (NilClass)
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:62:in `loop'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:62:in `go'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:78:in `block (3 levels) in go'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:78:in `fork'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:78:in `block (2 levels) in go'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:73:in `each'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:73:in `block in go'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:62:in `loop'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:62:in `go'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:78:in `block (3 levels) in go'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:78:in `fork'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:78:in `block (2 levels) in go'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:73:in `each'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:73:in `block in go'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:62:in `loop'
from /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:62:in `go'
from -e:1:in `<main>'
/Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/carrierwave-0.9.0/lib/carrierwave/uploader/store.rb:75:
(rdb:1) where
--> #1 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/carrierwave-0.9.0/lib/carrierwave/uploader/store.rb:75:in `rmdir'
#2 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/carrierwave-0.9.0/lib/carrierwave/uploader/store.rb:61:in `with_callbacks'
#3 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/carrierwave-0.9.0/lib/carrierwave/uploader/store.rb:58:in `store!'
#4 /Users/leo/Projects/PortfolioSite/test/uploaders/image_file_uploader_test.rb:38:in `test_upload_of_file'
#5 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1258:in `run'
#6 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:933:in `_run_suite'
#7 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/parallel_each.rb:71:in `_run_suites'
#8 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:877:in `_run_anything'
#9 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1085:in `run_tests'
#10 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1072:in `_run'
#11 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/minitest-4.7.5/lib/minitest/unit.rb:1059:in `run'
#12 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus/m.rb:203:in `execute'
#13 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus/m.rb:121:in `run'
#14 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus/m.rb:106:in `run'
#15 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus/rails.rb:190:in `test'
#16 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:116:in `command'
#17 /Users/leo/.rvm/gems/ruby-2.0.0-p195#portfolio_site/gems/zeus-0.13.3/lib/zeus.rb:80:in `go'
(rdb:1) up 3
#4 /Users/leo/Projects/PortfolioSite/test/uploaders/image_file_uploader_test.rb:38:in `test_upload_of_file'
(rdb:1) list
[33, 42] in /Users/leo/Projects/PortfolioSite/test/uploaders/image_file_uploader_test.rb
33 end
34
35 # The whole point of this is to upload a file.
36 def test_upload_of_file
37 uploader = ImageFileUploader.new
=> 38 uploader.store!(#file)
39 # Ensure the uploaded file is correct.
40 assert_equal Digest::SHA2.file(#file).hexdigest, Digest::SHA2.file("#{STORE_PATH}/#{FILENAME}").hexdigest
41 end
42
(rdb:1) p uploader.store!(#file)
[:store_versions!]
(rdb:1)
The code
Class being tested
class ImageFileUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
version :thumbnail do
process resize_to_fill: [100,100]
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
The test itself
require 'minitest/autorun'
require 'minitest/pride'
require 'minitest/debugger' if ENV['DEBUG']
require 'rmagick'
require 'carrierwave'
require_relative '../../app/uploaders/image_file_uploader'
class ImageFileUploaderTest < MiniTest::Unit::TestCase
# Before any tests run, set up parameters.
FILENAME = 'test_photo_1.jpg'
STORE_DIR = 'tmp/uploads/store'
CACHE_DIR = 'tmp/uploads/cache'
STORE_PATH = File.join __dir__, '..', '..', STORE_DIR
CACHE_PATH = File.join __dir__, '..', '..', CACHE_DIR
# Override the store and cache dirs so we’re not reliant on Rails.
class ::ImageFileUploader
storage :file
store_dir STORE_PATH
cache_dir CACHE_PATH
end
# Before each test runs, set up a file to test with.
def setup
#file = File.new "#{__dir__}/../test_files/#{FILENAME}"
end
# After each test runs, clear the results directory so it doesn't influence other tests.
def teardown
FileUtils.rm_rf STORE_PATH
FileUtils.rm_rf CACHE_PATH
end
# The whole point of this is to upload a file.
def test_upload_of_file
uploader = ImageFileUploader.new
uploader.store!(#file)
# Ensure the uploaded file is correct.
assert_equal Digest::SHA2.file(#file).hexdigest, Digest::SHA2.file("#{STORE_PATH}/#{FILENAME}").hexdigest
end
end
Simple Rake task
require 'rake/testtask'
Rake::TestTask.new('dev:test') do |t|
t.test_files = FileList['test/uploaders/*_test.rb']
end
Rails initializer (N.B. I think the test is isolated from this...)
CarrierWave.configure do |config|
config.storage = :file
# Override the directory where uploaded files will be stored.
config.store_dir = -> do
if model.nil?
"uploads/other/#{Time.now.strftime("%F")}/#{Time.now.strftime("%H-%M-%S")}"
else
# This is a sensible default for uploaders that are meant to be mounted:
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
# Override the directory where temp files will be stored.
config.cache_dir = -> do
# This is a better default because it prevents temp files from becoming public and is more consistent with the Rails directory structure.
Rails.root.join('tmp/uploads')
end
end
Thanks!

I have fixed this, although not through an entirely scientific process as I was changing other things in the code, including the overall Rails environment, as I went along.
The current, working version greatly simplifies the Carrierwave initializer, moving path definition to the uploader, and then monkey-patching those methods in the test.
Annoyingly, the original reason for the initializer-based approach was that custom directories were being picked up for the original image, but not for processed versions. That seems to be working fine now, but how this current code differs from the old one I’m not sure.
Rails initializer
CarrierWave.configure do |config|
config.storage = :file
end
Uploader
class ImageFileUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
version :thumbnail do
process resize_to_fill: [100,100]
end
def extension_white_list
%w(jpg jpeg gif png)
end
def store_dir
if model.nil?
"uploads/other/#{Time.now.strftime("%F")}/#{Time.now.strftime("%H-%M-%S")}"
else
# This is a sensible default for uploaders that are meant to be mounted:
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
def cache_dir
# This is a better default because it prevents temp files from becoming public and is more consistent with the Rails directory structure.
Rails.root.join('tmp/uploads')
end
end
Test
require_relative '../test_helper'
require 'rmagick'
require 'carrierwave'
require_relative '../../app/uploaders/image_file_uploader'
class ImageFileUploaderTest < MiniTest::Unit::TestCase
# Before any tests run, set up parameters.
FILENAME = 'test_photo_1.jpg'
STORE_DIR = 'tmp/uploads/store'
CACHE_DIR = 'tmp/uploads/cache'
STORE_PATH = File.join __dir__, '..', '..', STORE_DIR
CACHE_PATH = File.join __dir__, '..', '..', CACHE_DIR
# Override the store and cache dirs so we’re not reliant on Rails.
class ::ImageFileUploader
storage :file
def store_dir; STORE_PATH; end
def cache_dir; CACHE_PATH; end
end
# Before each test runs, set up a file to test with.
def setup
#file = File.new "#{__dir__}/../test_files/#{FILENAME}"
end
# After each test runs, clear the results directory so it doesn't influence other tests.
def teardown
FileUtils.rm_rf STORE_PATH
FileUtils.rm_rf CACHE_PATH
end
# The whole point of this is to upload a file.
def test_upload_of_file
uploader = ImageFileUploader.new
uploader.store!(#file)
# Ensure the uploaded file is correct.
assert_equal Digest::SHA2.file(#file).hexdigest, Digest::SHA2.file("#{STORE_PATH}/#{FILENAME}").hexdigest
end
# After each test, there is nothing to clean up, as teardown clears the output dir.
def after_tests
end
end
(N.B. The inclusion of test_helper is not relevant to the fix – after I had it working I moved some of the requires up to the helper to DRY up some overlap with other tests.)

Related

phusion passenger install hangs building CoreMain.cpp

On ubuntu-20 with ruby-2.6.6 and -3.0.4 installed via chruby, I have previously installed passenger 6.0.14 under 3.0.4. I need to install it (build mod_passenger.so) under ruby 2.6.6.
When I attempt to install, it hangs when compiling CoreMain.cpp.
The build process is started as follows:
Compiling and installing Apache 2 module...
cd /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14
# env NOEXEC_DISABLE=1 /opt/rubies/ruby-2.6.6/bin/ruby /opt/rubies/ruby-2.6.6/bin/rake RELEASE=yes apache2:clean apache2
rm -rf buildout/cache
...
It starts off building fine, but appears to slow down as it progresses.
At the end, it took 3 min to compile WatchdogMain.cpp, then starts on CoreMain.cpp.
After 20 minutes working on CoreMain.cpp, I get the following traceback when I interrupt the process:
c++ -o buildout/support-binaries/CoreMain.o -Isrc/agent -Isrc/cxx_supportlib -Isrc/cxx_supportlib/vendor-copy -Isrc/cxx_supportlib/vendor-modified -Isrc/cxx_supportlib/vendor-modified/libev -Isrc/cxx_supportlib/vendor-copy/libuv/include -Isrc/cxx_supportlib/vendor-modified/websocketpp -D_REENTRANT -I/usr/local/include -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-long-long -Wno-missing-field-initializers -feliminate-unused-debug-symbols -feliminate-unused-debug-types -fvisibility=hidden -DVISIBILITY_ATTRIBUTE_SUPPORTED -Wno-attributes -DHAS_ALLOCA_H -DHAVE_ACCEPT4 -DHAS_SFENCE -DHAS_LFENCE -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -ggdb -std=gnu++11 -Wno-unused-local-typedefs -Wno-format-nonliteral -DHAS_UNORDERED_MAP -c src/agent/Core/CoreMain.cpp
^C^C^C^CTraceback (most recent call last):
9: from /opt/rubies/ruby-2.6.6/bin/passenger-install-apache2-module:23:in `<main>'
8: from /opt/rubies/ruby-2.6.6/bin/passenger-install-apache2-module:23:in `load'
7: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/bin/passenger-install-apache2-module:964:in `<top (required)>'
6: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/src/ruby_supportlib/phusion_passenger/abstract_installer.rb:74:in `run'
5: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/bin/passenger-install-apache2-module:149:in `run_steps'
4: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/bin/passenger-install-apache2-module:424:in `compile_apache2_module'
3: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/src/ruby_supportlib/phusion_passenger/abstract_installer.rb:415:in `sh'
2: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/src/ruby_supportlib/phusion_passenger/abstract_installer.rb:415:in `system'
1: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/src/ruby_supportlib/phusion_passenger/abstract_installer.rb:415:in `initialize'
/opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/src/ruby_supportlib/phusion_passenger/abstract_installer.rb:415:in `initialize': Interrupt
/opt/rubies/ruby-2.6.6/bin/passenger-install-apache2-module: Interrupt
rake aborted!
Interrupt:
Tasks: TOP => apache2 => buildout/support-binaries/PassengerAgent => buildout/support-binaries/CoreMain.o
(See full trace by running task with --trace)
Traceback (most recent call last):
36: from /opt/rubies/ruby-2.6.6/bin/rake:23:in `<main>'
35: from /opt/rubies/ruby-2.6.6/bin/rake:23:in `load'
34: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
33: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:80:in `run'
32: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
31: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:83:in `block in run'
30: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:110:in `top_level'
29: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:125:in `run_with_threads'
28: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:116:in `block in top_level'
27: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:116:in `each'
26: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:116:in `block (2 levels) in top_level'
25: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:160:in `invoke_task'
24: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:183:in `invoke'
23: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:194:in `invoke_with_call_chain'
22: from /opt/rubies/ruby-2.6.6/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
21: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:213:in `block in invoke_with_call_chain'
20: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:236:in `invoke_prerequisites'
19: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:236:in `each'
18: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:238:in `block in invoke_prerequisites'
17: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:194:in `invoke_with_call_chain'
16: from /opt/rubies/ruby-2.6.6/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
15: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:213:in `block in invoke_with_call_chain'
14: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:236:in `invoke_prerequisites'
13: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:236:in `each'
12: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:238:in `block in invoke_prerequisites'
11: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:194:in `invoke_with_call_chain'
10: from /opt/rubies/ruby-2.6.6/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
9: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:214:in `block in invoke_with_call_chain'
8: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:273:in `execute'
7: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:273:in `each'
6: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/task.rb:273:in `block in execute'
5: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/build/support/cplusplus.rb:162:in `block in define_cxx_object_compilation_task'
4: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/build/support/cplusplus.rb:104:in `compile_cxx'
3: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/build/support/cplusplus.rb:31:in `run_compiler'
2: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/build/support/cplusplus.rb:31:in `system'
1: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/build/support/cplusplus.rb:31:in `initialize'
/opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/passenger-6.0.14/build/support/cplusplus.rb:31:in `initialize': Interrupt
7: from /opt/rubies/ruby-2.6.6/bin/rake:23:in `<main>'
6: from /opt/rubies/ruby-2.6.6/bin/rake:23:in `load'
5: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
4: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:80:in `run'
3: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:185:in `standard_exception_handling'
2: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:196:in `rescue in standard_exception_handling'
1: from /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:202:in `exit_because_of_exception'
/opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:202:in `exit': exit (SystemExit)
/opt/rubies/ruby-2.6.6/bin/rake: Interrupt

EXCEPTION_ACCESS_VIOLATION at 0x0 when calling dll compiled with Julia PackageCompiler

I am compiling Julia program as dll and trying to call from another program.
The Julia program is as follows (I am planning to use commented out pkg):
module pjname
# using Statistics
# using CSV
# using DataFrames
# using DSP
# # using Plots
# using Dates
# using FindPeaks1D
Base.#ccallable function function_name(slen::Cint)::Cint
println(1)
return 0
end
end # module
The program I am using to compile the code is:
using PackageCompiler
PackageCompiler.create_sysimage(; sysimage_path="./src/prog_dl.dll", script="./src/prog.jl")
and the program I call the dll is as follows:
using Libdl
libmg = dlopen("H:/julia/pjname3/src/prog_dl.dll")
function_name = dlsym(libmg, :func_name)
ccall(function_name, Cint, (Cint,), Int32(1))
I get the following error. Could someone help me to figure out this issue? I tried Julia version 1.6.5 and 1.7.0 but both of them didn't work. I am using windows and VS Code as IDE.
Please submit a bug report with steps to reproduce this fault, and any
error messages that follow (in their entirety). Thanks. Exception:
EXCEPTION_ACCESS_VIOLATION at 0x0 -- unknown function (ip:
0000000000000000) in expression starting at none:1 unknown
function (ip: 0000000000000000) function_name at
H:\julia\pjname3\src\prog_dl.dll (unknown line) top-level scope at
.\none:1 jl_toplevel_eval_flex at
/cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:871
jl_toplevel_eval at
/cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:886
[inlined] jl_toplevel_eval_in at
/cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:929
eval at .\boot.jl:360 [inlined] evaluate_foreigncall at
c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\JuliaInterpreter\src\interpret.jl:166
eval_rhs at
c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\JuliaInterpreter\src\interpret.jl:402
step_expr! at
c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\JuliaInterpreter\src\interpret.jl:556
step_expr! at
c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\JuliaInterpreter\src\interpret.jl:611
finish! at
c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\JuliaInterpreter\src\commands.jl:14
finish_and_return! at
c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\JuliaInterpreter\src\commands.jl:30
unknown function (ip: 0000000060da89d5) finish_stack! at
c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\JuliaInterpreter\src\commands.jl:60
unknown function (ip: 0000000060da8925)
#debug_command#83 at c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\JuliaInterpreter\src\commands.jl:474
debug_command at
c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\JuliaInterpreter\src\commands.jl:416
unknown function (ip: 0000000060dc8a09) jl_apply at
/cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703
[inlined] jl_f__call_latest at
/cygdrive/c/buildbot/worker/package_win64/build/src\builtins.c:714
#invokelatest#2 at .\essentials.jl:708 [inlined] invokelatest at .\essentials.jl:706 [inlined] our_debug_command at
c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\DebugAdapter\src\debugger_core.jl:67
startdebug at
c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\DebugAdapter\src\packagedef.jl:106
startdebugger at
c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\packages\VSCodeDebugger\src\VSCodeDebugger.jl:39
unknown function (ip: 0000000060d6bca3) jl_apply at
/cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703
[inlined] do_call at
/cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:115
eval_value at
/cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:204
eval_stmt_value at
/cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:155
[inlined] eval_body at
/cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:576
jl_interpret_toplevel_thunk at
/cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:670
jl_toplevel_eval_flex at
/cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:877
jl_toplevel_eval_flex at
/cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:825
jl_toplevel_eval at
/cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:886
[inlined] jl_toplevel_eval_in at
/cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:929
eval at .\boot.jl:360 [inlined] include_string at .\loading.jl:1116
_include at .\loading.jl:1170 include at .\Base.jl:384 exec_options at .\client.jl:285
_start at .\client.jl:485 jfptr__start_46900.clone_1 at C:\Users\user_name\AppData\Local\Programs\Julia-1.6.5\lib\julia\sys.dll
(unknown line) jl_apply at
/cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703
[inlined] true_main at
/cygdrive/c/buildbot/worker/package_win64/build/src\jlapi.c:560
repl_entrypoint at
/cygdrive/c/buildbot/worker/package_win64/build/src\jlapi.c:702
mainCRTStartup at
/cygdrive/c/buildbot/worker/package_win64/build/cli\loader_exe.c:51
BaseThreadInitThunk at C:\WINDOWS\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
Allocations: 14028713 (Pool: 14021110; Big: 7603); GC: 16 The terminal
process
"C:\Users\user_name\AppData\Local\Programs\Julia-1.6.5\bin\julia.exe
'--color=yes', '--startup-file=no', '--history-file=no',
'--project=h:\julia\pjname3',
'c:\Users\user_name.vscode\extensions\julialang.language-julia-1.5.8\scripts\debugger\run_debugger.jl',
'\.\pipe\vsc-jl-dbg-7bbf4da0-9e5b-4d64-8fbb-db76fd01a2af',
'\.\pipe\vsc-jl-cr-e192e8b6-1dd8-46c2-90a6-1074d122bd3c'" terminated
with exit code: 1.

How to subtract values in fastlane?

In my Fastfile I have method:
lane :calculate_build_version do
ENV['BUILD_NUMBER'] - BuildNumberFactory.make
end
BuldNumberFactory code is:
class BuildNumberFactory
class << self
def make
`git rev-list HEAD --count`
end
end
end
During build I get error:
Fastfile:22:in `block (2 levels) in parsing_binding': [!] undefined method `-' for "192":String (NoMethodError)
How can I fix this and perform subtract?

Huge amount of memory used by flink

Since the last couple week I build a DataStream programs in Flink in scala.
But I have a strange behavior, flink uses lots of more memory than I expected.
I have a 4 ListState of tuple(Int, long) in my processFunction keyed by INT, I use it to get different unique Counter in a different time frame, and I expected the most of the memory was used by this List.
But it's not the case.
So I print an histo live of the JVM.
And I was surprised how many memories are used.
num #instances #bytes class name
----------------------------------------------
1: 138920685 6668192880 java.util.HashMap$Node
2: 138893041 5555721640 org.apache.flink.streaming.api.operators.InternalTimer
3: 149680624 3592334976 java.lang.Integer
4: 48313229 3092046656 org.apache.flink.runtime.state.heap.CopyOnWriteStateTable$StateTableEntry
5: 14042723 2579684280 [Ljava.lang.Object;
6: 4492 2047983264 [Ljava.util.HashMap$Node;
7: 41686732 1333975424 com.myJob.flink.tupleState
8: 201 784339688 [Lorg.apache.flink.runtime.state.heap.CopyOnWriteStateTable$StateTableEntry;
9: 17230300 689212000 com.myJob.flink.uniqStruct
10: 14025040 561001600 java.util.ArrayList
11: 8615581 413547888 com.myJob.flink.Data$FingerprintCnt
12: 6142006 393088384 com.myJob.flink.ProcessCountStruct
13: 4307549 172301960 com.myJob.flink.uniqresult
14: 4307841 137850912 com.myJob.flink.Data$FingerprintUniq
15: 2153904 137849856 com.myJob.flink.Data$StreamData
16: 1984742 79389680 scala.collection.mutable.ListBuffer
17: 1909472 61103104 scala.collection.immutable.$colon$colon
18: 22200 21844392 [B
19: 282624 9043968 org.apache.flink.shaded.netty4.io.netty.buffer.PoolThreadCache$MemoryRegionCache$Entry
20: 59045 6552856 [C
21: 33194 2655520 java.nio.DirectByteBuffer
22: 32804 2361888 sun.misc.Cleaner
23: 35 2294600 [Lscala.concurrent.forkjoin.ForkJoinTask;
24: 640 2276352 [Lorg.apache.flink.shaded.netty4.io.netty.buffer.PoolThreadCache$MemoryRegionCache$Entry;
25: 32768 2097152 org.apache.flink.core.memory.HybridMemorySegment
26: 12291 2082448 java.lang.Class
27: 58591 1874912 java.lang.String
28: 8581 1372960 java.lang.reflect.Method
29: 32790 1311600 java.nio.DirectByteBuffer$Deallocator
30: 18537 889776 java.util.concurrent.ConcurrentHashMap$Node
31: 4239 508680 java.lang.reflect.Field
32: 8810 493360 java.nio.HeapByteBuffer
33: 7389 472896 java.util.HashMap
34: 5208 400336 [I
The tupple(Int, long) is com.myJob.flink.tupleState in 7th position.
And I see the tuple use less than 2G of memory.
I don't understand why flink used this amount of memory for these classes.
Can anyone give me a light on this behavior, thanks in advance.
Update:
I run my job on a stand alone cluster (1 jobManager, 3 taskManager)
the flink version is 1.5-SNAPSHOT commit : e4486ae
I get the histo live on one taskManager node.
Update 2 :
In my processFunction I used :
ctx.timerService.registerProcessingTimeTimer(ctx.timestamp + 100)
And after on onTimer function, I process my listState to check all old data.
so it create a timer for each call on processFunction.
but why the timer is steel on memory after onTimer function triggered
How many windows do you end up with? Based on the top two entries what are are seeing is the "timers" that are used by Flink to track when to clean up the window. For every key in the window you will end up with (key, endTimestamp) effectively in the timer state. If you have a very large number of windows (perhaps out of order time or delayed watermarking) or a very large number of keys in each window, those will each take up memory.
Note that even if you are using RocksDB state, the TimerService uses Heap memory so you have to watch out for that.

[AVPlaybackItem fpItem]: message sent to deallocated instance

I play a movie with MPMoviePlayerController. Later, the app is "restarted" (meaning a pseudo-reset, where all viewControllers are removed and the user returns to the home screen), and the same movie is played again.
This leads to a crash in iOS 3.2.2 on the iPad:
[AVPlaybackItem fpItem]: message sent
to deallocated instance
I have no idea where that comes from. Seems to be something private. Has anyone experienced and possibly solved the same problem?
The stack trace for that particular address:
(gdb) info malloc 0x11471400
Alloc: Block address: 0x11471400 length: 76
Stack - pthread: 0xa0630500 number of frames: 34
0: 0x9534e0c3 in malloc_zone_calloc
1: 0x9534e01a in calloc
2: 0x343edc9 in _internal_class_createInstanceFromZone
3: 0x344b5c9 in _class_createInstanceFromZone
4: 0x344b5ef in class_createInstance
5: 0x3326b57 in +[NSObject allocWithZone:]
6: 0x332583a in +[NSObject alloc]
7: 0x536ab67 in -[AVPlaybackQueue queueItemWasAddedNotification:]
8: 0x27f586 in _nsnote_callback
9: 0x328d165 in _CFXNotificationPostNotification
10: 0x2762ca in -[NSNotificationCenter postNotificationName:object:userInfo:]
11: 0x5354982 in -[AVQueue itemWasAdded:atIndex:]
12: 0x5354801 in -[AVQueue insertItem:atIndex:error:]
13: 0x53549d8 in -[AVQueue appendItem:error:]
14: 0x535c3be in -[AVController addNextFeederItemToQueue]
15: 0x535b06f in -[AVController checkQueueSpace]
16: 0x5359f46 in -[AVController setQueue:]
17: 0x535ac62 in -[AVController setQueueFeeder:withIndex:]
18: 0x30eee20 in -[MPAVController reloadFeederWithStartIndex:]
19: 0x30deed7 in -[MPMoviePlayerControllerNew _prepareToPlayWithStartIndex:]
20: 0x30dc686 in -[MPMoviePlayerControllerNew prepareToPlay]
21: 0x27f586 in _nsnote_callback
22: 0x328d165 in _CFXNotificationPostNotification
23: 0x2762ca in -[NSNotificationCenter postNotificationName:object:userInfo:]
24: 0x281238 in -[NSNotificationCenter postNotificationName:object:]
25: 0x31596d1 in -[MPMovie _determineMediaType]
26: 0x291b87 in __NSFireDelayedPerform
27: 0x32747dc in CFRunLoopRunSpecific
28: 0x32738a8 in CFRunLoopRunInMode
29: 0x3aaf89d in GSEventRunModal
30: 0x3aaf962 in GSEventRun
31: 0x52b372 in UIApplicationMain
32: 0x27be in main at /blablabla
33: 0x2735 in start
It sounds like you're calling release more than you are calling retain.
Does the error message not contain a hex address at the end? If it does, follow these steps to hunt down the offending object:
Navigate to Project->Edit Active Executable (or press Command-Option-X). Choose the arguments tab. Set the environmental variables as shown below:
Run the program and repeat the steps needed to reproduce the error.
Copy the hex address at the end of the error. Then, in the debugger console type this command: (gdb) info malloc-history <paste-address-here>.
Examine the output to hunt down the offending object.
P.S. Don't forget to disable the environmental variables when you're done.
maybe you call prepare to play more than once for the same movie and i think this is the problem and it exists to all ios prior to 4.3 i guess (not sure though) so just flag the movie if prepare to play was called once then don't recall it for the same file