| | 140 | |
|---|
| | 141 | #------------------------------------ |
|---|
| | 142 | # |
|---|
| | 143 | # TODO. This is an unfinished bug fix. |
|---|
| | 144 | # This case was originally reported by Dan Aquino. If you throw a Ruby exception |
|---|
| | 145 | # in a post_init handler, it gets rethrown as a confusing reactor exception. |
|---|
| | 146 | # The problem is in eventmachine.rb, which calls post_init within the private |
|---|
| | 147 | # initialize method of the EM::Connection class. This happens in both the EM::connect |
|---|
| | 148 | # method and in the code that responds to connection-accepted events. |
|---|
| | 149 | # What happens is that we instantiate the new connection object, which calls |
|---|
| | 150 | # initialize, and then after initialize returns, we stick the new connection object |
|---|
| | 151 | # into EM's @conns hashtable. |
|---|
| | 152 | # But the problem is that Connection::initialize calls #post_init before it returns, |
|---|
| | 153 | # and this may be user-written code that may throw an uncaught Ruby exception. |
|---|
| | 154 | # If that happens, the reactor will abort, and it will then try to run down open |
|---|
| | 155 | # connections. Because @conns never got a chance to properly reflect the new connection |
|---|
| | 156 | # (because initialize never returned), we throw a ConnectionNotBound error |
|---|
| | 157 | # (eventmachine.rb line 1080). |
|---|
| | 158 | # When the bug is fixed, activate this test case. |
|---|
| | 159 | # |
|---|
| | 160 | |
|---|
| | 161 | class PostInitError < EM::Connection |
|---|
| | 162 | def post_init |
|---|
| | 163 | aaa bbb # should produce a Ruby exception |
|---|
| | 164 | end |
|---|
| | 165 | end |
|---|
| | 166 | def test_post_init_error |
|---|
| | 167 | assert_raise( NameError ) { |
|---|
| | 168 | EM.run { |
|---|
| | 169 | EM::Timer.new(1) {EM.stop} |
|---|
| | 170 | EM.start_server TestHost, TestPort |
|---|
| | 171 | EM.connect TestHost, TestPort, PostInitError |
|---|
| | 172 | } |
|---|
| | 173 | } |
|---|
| | 174 | end |
|---|
| | 175 | |
|---|
| | 176 | |
|---|