{"action":"created","issue":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/3996","repository_url":"https://api.github.com/repos/crystal-lang/crystal","labels_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3996/labels{/name}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3996/comments","events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3996/events","html_url":"https://github.com/crystal-lang/crystal/issues/3996","id":205257091,"number":3996,"title":"exception in finalize halts program?","user":{"login":"rdp","id":12496,"avatar_url":"https://avatars.githubusercontent.com/u/12496?v=3","gravatar_id":"","url":"https://api.github.com/users/rdp","html_url":"https://github.com/rdp","followers_url":"https://api.github.com/users/rdp/followers","following_url":"https://api.github.com/users/rdp/following{/other_user}","gists_url":"https://api.github.com/users/rdp/gists{/gist_id}","starred_url":"https://api.github.com/users/rdp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rdp/subscriptions","organizations_url":"https://api.github.com/users/rdp/orgs","repos_url":"https://api.github.com/users/rdp/repos","events_url":"https://api.github.com/users/rdp/events{/privacy}","received_events_url":"https://api.github.com/users/rdp/received_events","type":"User","site_admin":false},"labels":[{"id":530992275,"url":"https://api.github.com/repos/crystal-lang/crystal/labels/community:to-research","name":"community:to-research","color":"bfd4f2","default":false},{"id":20487867,"url":"https://api.github.com/repos/crystal-lang/crystal/labels/kind:bug","name":"kind:bug","color":"fc2929","default":false},{"id":253019637,"url":"https://api.github.com/repos/crystal-lang/crystal/labels/topic:compiler","name":"topic:compiler","color":"fef2c0","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2017-02-03T20:09:50Z","updated_at":"2017-02-20T05:32:48Z","closed_at":null,"body":"```\r\nclass Foo\r\n  def finalize\r\n    # Invoked when Foo is garbage-collected\r\n    puts \"Bye bye from #{self}!\"\r\n    raise \"boom\"\r\n  end\r\nend\r\n\r\nloop do\r\n  Foo.new\r\nend\r\n```\r\n\r\nOutput:\r\n```\r\n$ crystal bad.cr\r\nBye bye from #<Foo:0x10e4fb600>!\r\nBye bye from #<Foo:0x10d4a56a0>!\r\nboom (Exception)\r\nBye bye from #<Foo:0x10e4fb610>!\r\nFailed to raise an exception: END_OF_STACK\r\n[4516129659] *CallStack::print_backtrace:Int32 +107\r\n[4516089934] __crystal_raise +78\r\n[4516090489] *raise<Exception>:NoReturn +137\r\n[4516090337] *raise<String>:NoReturn +17\r\n[4516272930] *Foo#finalize:NoReturn +98\r\n[4516104049] ~procProc(Pointer(Void), Pointer(Void), NoReturn)@/usr/local/Cellar/crystal-lang/0.20.5/src/gc/boehm.cr:108 +17\r\n[4516960480] GC_invoke_finalizers +172\r\n[4516960815] GC_notify_or_invoke_finalizers +174\r\n[4516965813] GC_generic_malloc +37\r\n[4516966426] GC_malloc_kind_global +234\r\n[4516091835] __crystal_malloc_atomic +11\r\n[4516150585] *GC::malloc_atomic<UInt32>:Pointer(Void) +9\r\n[4516149150] *String#byte_slice<Int32, Int32>:String +286\r\n[4516147828] *String#[]<Int32, Int32>:String +84\r\n[4516194373] *File::basename<String>:String +213\r\n[4516108698] *CallStack::dwarf_line_numbers:(Debug::DWARF::LineNumbers | Nil) +474\r\n[4516107582] *CallStack::decode_line_number<Pointer(Void)>:Tuple(String | Nil, Int32, Int32) +30\r\n[4516106830] *CallStack#decode_backtrace:Array(String) +142\r\n[4516106657] *CallStack#printable_backtrace:Array(String) +49\r\n[4516193688] *Exception+@Exception#backtrace?:(Array(String) | Nil) +72\r\n[4516192990] *Exception+@Exception#inspect_with_backtrace<IO::FileDescriptor>:IO::FileDescriptor +110\r\n[4516103854] main +142\r\n```\r\nand program hard exits.\r\n\r\nI might be expect it to output the exception to the screen, but not to hard exit.\r\n\r\nAlso with that snippet without the raise line, on OS X 1/3 times I get this hard failure immediately:\r\n\r\n```\r\nInvalid memory access (signal 11) at address 0x0\r\n[4454657387] *CallStack::print_backtrace:Int32 +107\r\n[4454631735] __crystal_sigfault_handler +55\r\n[4454804579] sigfault_handler +35\r\n[140735613365178] _sigtramp +26\r\n[4454699622] *Pointer(Fiber)@Pointer(T)#[]=<Int32, Fiber>:Fiber +22\r\n[4454697338] *Deque(Fiber)@Deque(T)#push<Fiber>:Deque(Fiber) +106\r\n[4454697225] *Deque(Fiber)@Deque(T)#<<<Fiber>:Deque(Fiber) +9\r\n[4454703792] *IO::FileDescriptor#wait_writable<(Float64 | Nil)>:Nil +160\r\n[4454703613] *IO::FileDescriptor#wait_writable:Nil +45\r\n[4454702955] *IO::FileDescriptor#unbuffered_write<Slice(UInt8)>:Int32 +555\r\n[4454703957] *IO::FileDescriptor@IO::Buffered#flush:IO::FileDescriptor +69\r\n[4454704340] *IO::FileDescriptor@IO::Buffered#write_byte<UInt8>:(IO::FileDescriptor | Int32 | Nil) +180\r\n[4454692018] *Char#to_s<IO::FileDescriptor>:(IO::FileDescriptor | Int32 | Nil) +210\r\n[4454704135] *IO::FileDescriptor@IO#<<<Char>:IO::FileDescriptor +23\r\n[4454704093] *IO::FileDescriptor@IO#print<Char>:Nil +13\r\n[4454704078] *IO::FileDescriptor@IO#puts:Nil +14\r\n[4454701352] *IO::FileDescriptor@IO#puts<String>:Nil +56\r\n[4454631833] *puts<String>:Nil +41\r\n[4454803475] *Foo#finalize:Nil +83\r\n[4454631777] ~proc5Proc(Pointer(Void), Pointer(Void), Nil)@/Users/packrd/dev/ruby/downloads/crystal/src/gc/boehm.cr:108 +17\r\n[4455479520] GC_invoke_finalizers +172\r\n[4455479855] GC_notify_or_invoke_finalizers +174\r\n[4455484853] GC_generic_malloc +37\r\n[4455485466] GC_malloc_kind_global +234\r\n[4454617019] __crystal_malloc +11\r\n[4454699273] *Pointer(Fiber)@Pointer(T)::malloc<Int32>:Pointer(Fiber) +73\r\n[4454697430] *Deque(Fiber)@Deque(T)#increase_capacity:(Int32 | Nil) +54\r\n[4454697269] *Deque(Fiber)@Deque(T)#push<Fiber>:Deque(Fiber) +37\r\n[4454697225] *Deque(Fiber)@Deque(T)#<<<Fiber>:Deque(Fiber) +9\r\n[4454703792] *IO::FileDescriptor#wait_writable<(Float64 | Nil)>:Nil +160\r\n[4454703613] *IO::FileDescriptor#wait_writable:Nil +45\r\n[4454702955] *IO::FileDescriptor#unbuffered_write<Slice(UInt8)>:Int32 +555\r\n[4454703957] *IO::FileDescriptor@IO::Buffered#flush:IO::FileDescriptor +69\r\n[4454704340] *IO::FileDescriptor@IO::Buffered#write_byte<UInt8>:(IO::FileDescriptor | Int32 | Nil) +180\r\n[4454692018] *Char#to_s<IO::FileDescriptor>:(IO::FileDescriptor | Int32 | Nil) +210\r\n[4454704135] *IO::FileDescriptor@IO#<<<Char>:IO::FileDescriptor +23\r\n[4454704093] *IO::FileDescriptor@IO#print<Char>:Nil +13\r\n[4454704078] *IO::FileDescriptor@IO#puts:Nil +14\r\n[4454701352] *IO::FileDescriptor@IO#puts<String>:Nil +56\r\n[4454631833] *puts<String>:Nil +41\r\n[4454803475] *Foo#finalize:Nil +83\r\n[4454631777] ~proc5Proc(Pointer(Void), Pointer(Void), Nil)@/Users/packrd/dev/ruby/downloads/crystal/src/gc/boehm.cr:108 +17\r\n[4455479520] GC_invoke_finalizers +172\r\n[4455479855] GC_notify_or_invoke_finalizers +174\r\n[4455484853] GC_generic_malloc +37\r\n[4455485466] GC_malloc_kind_global +234\r\n[4454619563] __crystal_malloc_atomic +11\r\n[4454678425] *GC::malloc_atomic<UInt32>:Pointer(Void) +9\r\n[4454668467] *String::Builder#initialize:Bool +51\r\n[4454668385] *String::Builder::new:String::Builder +129\r\n[4454803409] *Foo#finalize:Nil +17\r\n[4454631777] ~proc5Proc(Pointer(Void), Pointer(Void), Nil)@/Users/packrd/dev/ruby/downloads/crystal/src/gc/boehm.cr:108 +17\r\n[4455479520] GC_invoke_finalizers +172\r\n[4455479855] GC_notify_or_invoke_finalizers +174\r\n[4455487382] GC_generic_malloc_many +67\r\n[4455517170] GC_malloc_kind +163\r\n[4454617019] __crystal_malloc +11\r\n[4454803337] *Foo@Reference::new:Foo +25\r\n[4454616984] __crystal_main +1128\r\n[4454631480] main +40\r\n```\r\n\r\ncan't seem to repro it in inux, possibly a timing thing."},"comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments/280991895","html_url":"https://github.com/crystal-lang/crystal/issues/3996#issuecomment-280991895","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3996","id":280991895,"user":{"login":"rdp","id":12496,"avatar_url":"https://avatars.githubusercontent.com/u/12496?v=3","gravatar_id":"","url":"https://api.github.com/users/rdp","html_url":"https://github.com/rdp","followers_url":"https://api.github.com/users/rdp/followers","following_url":"https://api.github.com/users/rdp/following{/other_user}","gists_url":"https://api.github.com/users/rdp/gists{/gist_id}","starred_url":"https://api.github.com/users/rdp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rdp/subscriptions","organizations_url":"https://api.github.com/users/rdp/orgs","repos_url":"https://api.github.com/users/rdp/repos","events_url":"https://api.github.com/users/rdp/events{/privacy}","received_events_url":"https://api.github.com/users/rdp/received_events","type":"User","site_admin":false},"created_at":"2017-02-20T05:32:48Z","updated_at":"2017-02-20T05:32:48Z","body":"Moving discussion of the dequeue trace to #4013 FWIW."}}
{"actor":{"display_login":"rdp"}}