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

Crash depending on require order #7060

Closed
felixbuenemann opened this issue Nov 11, 2018 · 5 comments · Fixed by #8234
Closed

Crash depending on require order #7060

felixbuenemann opened this issue Nov 11, 2018 · 5 comments · Fixed by #8234

Comments

@felixbuenemann
Copy link
Contributor

There's a crash in Crystal 0.27.0 that did not happen in 0.26.1 when using minitest.cr (0.4.0 for 0.26.1 / 0.4.2 for 0.27.0) and HTTP::Client in the same file that depends on the order of the minitest/autorun and http/client requires.

The following example works:

require "http/client"
require "minitest/autorun"

class FooTest < Minitest::Test
  def test_http_client
    response = HTTP::Client.get("http://www.example.org")
    assert_equal true, response.success?
  end
end

However the following code crashes (require order switched):

require "minitest/autorun"
require "http/client"

class FooTest < Minitest::Test
  def test_http_client
    response = HTTP::Client.get("http://www.example.org")
    assert_equal true, response.success?
  end
end
Module validation failed: !dbg attachment points at wrong subprogram for function
!10 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !5, file: !5, line: 115, type: !6, isLocal: true, isDefinition: true, scopeLine: 115, isOptimized: false, unit: !0, variables: !2)
i8* (%"OpenSSL::BIO"*, %TCPSocket*)* @"*OpenSSL::BIO#initialize<TCPSocket>:Pointer(Void)"
  %2 = call %"struct.LibCrypto::BioMethod"** @"~OpenSSL::BIO::CRYSTAL_BIO:read"(), !dbg !12
!12 = !DILocation(line: 13, column: 3, scope: !13)
!13 = distinct !DISubprogram(name: "set_data", linkageName: "set_data", scope: !5, file: !5, line: 13, type: !6, isLocal: true, isDefinition: true, scopeLine: 13, isOptimized: false, unit: !0, variables: !2)
!13 = distinct !DISubprogram(name: "set_data", linkageName: "set_data", scope: !5, file: !5, line: 13, type: !6, isLocal: true, isDefinition: true, scopeLine: 13, isOptimized: false, unit: !0, variables: !2)
 (Exception)
  from Crystal::CodeGenVisitor#finish:Nil
  from Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil)
  from Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result
  from Crystal::Command#run_command<Bool>:Nil
  from Crystal::Command#run:(Bool | Crystal::Compiler::Result | Nil)
  from __crystal_main
  from main
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

Example entry for shard.yml:

development_dependencies:
  minitest:
    github: ysbaddaden/minitest.cr

System info:

$ crystal -v
Crystal 0.27.0 (2018-11-04)

LLVM: 6.0.1
Default target: x86_64-apple-macosx

System is macOS Mojave 10.14.1 and Crystal was installed from Homebrew using the precompiled bottle for Mojave.

Maybe @ysbaddaden (author of minitest.cr) has an idea what could be causing this.

@asterite
Copy link
Member

It's probably a compiler bug. Just require stuff in the correct order as a workaround.

@ysbaddaden
Copy link
Contributor

ysbaddaden commented Nov 11, 2018

It's a compiler bug. It happened to me numerous times the last few months. The only workaround it to run with --no-debug 😞

Duplicate of #6920

@felixbuenemann
Copy link
Contributor Author

Thanks for the update, I wasn’t sure it was the same issue as #6920 since it only started for me on 0.27.0 and the issue was older than that release.

@ysbaddaden
Copy link
Contributor

We changed OpenSSL to support v1.1 which changed BIO, and it seems to trigger the bug.

Nice to know that we can require the app before minitest/autorun to avoid this.

@xqyww123
Copy link
Contributor

xqyww123 commented Jul 8, 2019

--no-debug saves my half day.

icy-arctic-fox added a commit to icy-arctic-fox/spectator that referenced this issue Aug 22, 2019
Fix for GitHub issue 1 - 
#1
Works around Crystal issue 7060 (6920) - 
crystal-lang/crystal#7060

This should be reverted after it is fixed in the Crystal compiler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@ysbaddaden @asterite @felixbuenemann @xqyww123 and others