Forum: Ruby-core [Ruby 1.9 - Bug #5218][Open] at_exit bug with exception handling

Posted by Edgars Beigarts (Guest)
on 2011-08-23 16:51
(Received via mailing list)
Issue #5218 has been reported by Edgars Beigarts.

----------------------------------------
Bug #5218: at_exit bug with exception handling
http://redmine.ruby-lang.org/issues/5218

Author: Edgars Beigarts
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) 
[x86_64-darwin10.8.0]


It seems that ruby 1.9.2 and later doesn't like exception handling in 
`at_exit` blocks and resets the exit code to 0.

Here is an example:

    #!/usr/bin/ruby

    at_exit do
      raise "X" rescue nil
    end

    at_exit do
      nil
    end

    at_exit do
      exit 1
    end

    at_exit do
      exit 2
    end

Results:


    ### ruby 1.9.4dev (2011-08-23 trunk 33027) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.9.3dev (2011-07-31 revision 32789) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    1

    ### jruby 1.6.3 (ruby-1.8.7-p330) (2011-07-07 965162f) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]

    $ jruby at_exit.rb ; echo $?
    1

    ### jruby 1.6.3 (ruby-1.9.2-p136) (2011-07-07 965162f) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]

    $ jruby --1.9 at_exit.rb ; echo $?
    1


Related issues:

https://github.com/jnicklas/capybara/pull/463
https://github.com/jnicklas/capybara/issues/178
https://github.com/rspec/rspec-core/pull/410
Posted by Edgars Beigarts (Guest)
on 2011-08-24 09:23
(Received via mailing list)
Issue #5218 has been updated by Edgars Beigarts.


To fix ruby 1.9 I came up with this workaround:

if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= 
"1.9"
  module Kernel
    alias :__at_exit :at_exit
    def at_exit(&block)
      __at_exit do
        exit_status = $!.status if $!.is_a?(SystemExit)
        block.call
        exit exit_status if exit_status
      end
    end
  end
end
----------------------------------------
Bug #5218: at_exit bug with exception handling
http://redmine.ruby-lang.org/issues/5218

Author: Edgars Beigarts
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) 
[x86_64-darwin10.8.0]


It seems that ruby 1.9.2 and later doesn't like exception handling in 
`at_exit` blocks and resets the exit code to 0.

Here is an example:

    #!/usr/bin/ruby

    at_exit do
      raise "X" rescue nil
    end

    at_exit do
      nil
    end

    at_exit do
      exit 1
    end

    at_exit do
      exit 2
    end

Results:


    ### ruby 1.9.4dev (2011-08-23 trunk 33027) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.9.3dev (2011-07-31 revision 32789) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    1

    ### jruby 1.6.3 (ruby-1.8.7-p330) (2011-07-07 965162f) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]

    $ jruby at_exit.rb ; echo $?
    1

    ### jruby 1.6.3 (ruby-1.9.2-p136) (2011-07-07 965162f) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]

    $ jruby --1.9 at_exit.rb ; echo $?
    1


Related issues:

https://github.com/jnicklas/capybara/pull/463
https://github.com/jnicklas/capybara/issues/178
https://github.com/rspec/rspec-core/pull/410
Posted by Koichi Sasada (Guest)
on 2012-03-11 07:19
(Received via mailing list)
Issue #5218 has been updated by Koichi Sasada.

Status changed from Open to Assigned
Assignee set to Nobuyoshi Nakada


----------------------------------------
Bug #5218: at_exit bug with exception handling
https://bugs.ruby-lang.org/issues/5218

Author: Edgars Beigarts
Status: Assigned
Priority: Normal
Assignee: Nobuyoshi Nakada
Category:
Target version:
ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) 
[x86_64-darwin10.8.0]


It seems that ruby 1.9.2 and later doesn't like exception handling in 
`at_exit` blocks and resets the exit code to 0.

Here is an example:

    #!/usr/bin/ruby

    at_exit do
      raise "X" rescue nil
    end

    at_exit do
      nil
    end

    at_exit do
      exit 1
    end

    at_exit do
      exit 2
    end

Results:


    ### ruby 1.9.4dev (2011-08-23 trunk 33027) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.9.3dev (2011-07-31 revision 32789) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    1

    ### jruby 1.6.3 (ruby-1.8.7-p330) (2011-07-07 965162f) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]

    $ jruby at_exit.rb ; echo $?
    1

    ### jruby 1.6.3 (ruby-1.9.2-p136) (2011-07-07 965162f) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]

    $ jruby --1.9 at_exit.rb ; echo $?
    1


Related issues:

https://github.com/jnicklas/capybara/pull/463
https://github.com/jnicklas/capybara/issues/178
https://github.com/rspec/rspec-core/pull/410
Posted by rubiii (Daniel Harrington) (Guest)
on 2012-11-29 12:46
(Received via mailing list)
Issue #5218 has been updated by rubiii (Daniel Harrington).


Hi guys,

thank you for this fix!
Any information about when it's going to be released?

Cheers,
Daniel

----------------------------------------
Bug #5218: at_exit bug with exception handling
https://bugs.ruby-lang.org/issues/5218#change-34142

Author: ebeigarts (Edgars Beigarts)
Status: Closed
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category:
Target version:
ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) 
[x86_64-darwin10.8.0]


It seems that ruby 1.9.2 and later doesn't like exception handling in 
`at_exit` blocks and resets the exit code to 0.

Here is an example:

    #!/usr/bin/ruby

    at_exit do
      raise "X" rescue nil
    end

    at_exit do
      nil
    end

    at_exit do
      exit 1
    end

    at_exit do
      exit 2
    end

Results:


    ### ruby 1.9.4dev (2011-08-23 trunk 33027) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.9.3dev (2011-07-31 revision 32789) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    1

    ### jruby 1.6.3 (ruby-1.8.7-p330) (2011-07-07 965162f) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]

    $ jruby at_exit.rb ; echo $?
    1

    ### jruby 1.6.3 (ruby-1.9.2-p136) (2011-07-07 965162f) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]

    $ jruby --1.9 at_exit.rb ; echo $?
    1


Related issues:

https://github.com/jnicklas/capybara/pull/463
https://github.com/jnicklas/capybara/issues/178
https://github.com/rspec/rspec-core/pull/410
Posted by Michiel De mare (mdemare)
on 2013-02-19 13:19
(Received via mailing list)
Issue #5218 has been updated by mdemare (Michiel de MAre).


So what happened to the changeset? It's still broken in 1.9.3-p385.
----------------------------------------
Bug #5218: at_exit bug with exception handling
https://bugs.ruby-lang.org/issues/5218#change-36609

Author: ebeigarts (Edgars Beigarts)
Status: Closed
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category:
Target version:
ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) 
[x86_64-darwin10.8.0]


It seems that ruby 1.9.2 and later doesn't like exception handling in 
`at_exit` blocks and resets the exit code to 0.

Here is an example:

    #!/usr/bin/ruby

    at_exit do
      raise "X" rescue nil
    end

    at_exit do
      nil
    end

    at_exit do
      exit 1
    end

    at_exit do
      exit 2
    end

Results:


    ### ruby 1.9.4dev (2011-08-23 trunk 33027) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.9.3dev (2011-07-31 revision 32789) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    0

    ### ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10.8.0]

    $ ruby at_exit.rb ; echo $?
    1

    ### jruby 1.6.3 (ruby-1.8.7-p330) (2011-07-07 965162f) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]

    $ jruby at_exit.rb ; echo $?
    1

    ### jruby 1.6.3 (ruby-1.9.2-p136) (2011-07-07 965162f) (Java 
HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]

    $ jruby --1.9 at_exit.rb ; echo $?
    1


Related issues:

https://github.com/jnicklas/capybara/pull/463
https://github.com/jnicklas/capybara/issues/178
https://github.com/rspec/rspec-core/pull/410
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.