Closed sayakahojo closed 6 years ago
If you follow your own link you will know what the purpose of that code is: if the loop thread raises an error, to not silently ignore it and raise it in the main thread.
BTW, you are referencing old code (2 versions ago). In recent versions, the code allows to set an error
callback on client, so that socket errors do not interrupt the main thread.
From the README:
- on(event, &block)
Allows to set a callback for the client. The only available event is
:error
, which allows to set a callback when an error is raised at socket level, hence in the underlying socket thread.client.on(:error) { |exception| puts "Exception has been raised: #{exception}" }
It is RECOMMENDED to set the
:error
callback: if none is defined, the underlying socket thread may raise an error in the main thread at unexpected execution times.
When socket error occured, net-http2 kills ruby interpreter process. It causes temporary error when it is used for application.
Here is the code. https://github.com/ostinelli/net-http2/blob/1513fb7cb661bfcc6648ef31fbc3b66095dacc51/lib/net-http2/client.rb#L101
abort_on_exception method is called after socket error and it must be destructive.
↓ I want to know what the purpose of this code is. end.tap { |t| t.abort_on_exception = true }
https://ruby-doc.org/core-1.9.3/Thread.html