Crystal: Crash depending on require order

Created on 11 Nov 2018  路  5Comments  路  Source: crystal-lang/crystal

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.

bug topicdebugger

All 5 comments

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

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

Duplicate of https://github.com/crystal-lang/crystal/issues/6920

Thanks for the update, I wasn鈥檛 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.

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.

--no-debug saves my half day.

Was this page helpful?
0 / 5 - 0 ratings