Skip to content

Commit

Permalink
Don't modify a frozen object in SSL resolver.
Browse files Browse the repository at this point in the history
Sometimes it happens that when submitting forms under https://, I get a crash
because WWW::Mechanize::Chain::SSLResolver tries to change its connection
and the connection is frozen:

TypeError: can't modify frozen object
  from /usr/lib/ruby/1.8/net/https.rb:138:in `verify_mode='
  from /usr/lib/ruby/1.8/net/https.rb:138:in `verify_mode='
  from ./lib/www/mechanize/chain/ssl_resolver.rb:20:in `handle'
  from ./lib/www/mechanize/chain.rb:30:in `pass'
  from ./lib/www/mechanize/chain/handler.rb:6:in `handle'
  from ./lib/www/mechanize/chain/connection_resolver.rb:73:in `handle'
  from ./lib/www/mechanize/chain.rb:30:in `pass'
  from ./lib/www/mechanize/chain/handler.rb:6:in `handle'
  from ./lib/www/mechanize/chain/request_resolver.rb:27:in `handle'
  from ./lib/www/mechanize/chain.rb:30:in `pass'
  from ./lib/www/mechanize/chain/handler.rb:6:in `handle'
  from ./lib/www/mechanize/chain/parameter_resolver.rb:18:in `handle'
  from ./lib/www/mechanize/chain.rb:30:in `pass'
  from ./lib/www/mechanize/chain/handler.rb:6:in `handle'
  from ./lib/www/mechanize/chain/uri_resolver.rb:51:in `handle'
  from ./lib/www/mechanize/chain.rb:25:in `handle'
  from ./lib/www/mechanize.rb:434:in `fetch_page'
  from ./lib/www/mechanize.rb:393:in `post_form'
  from ./lib/www/mechanize.rb:325:in `submit'
  • Loading branch information
terceiro committed Oct 21, 2008
1 parent 51a313f commit 88762d4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/www/mechanize/chain/ssl_resolver.rb
Expand Up @@ -15,7 +15,7 @@ def initialize(ca_file, verify_callback, cert, key, pass)
def handle(ctx, params)
uri = params[:uri]
http_obj = params[:connection]
if uri.scheme == 'https' && ! http_obj.started?
if uri.scheme == 'https' && ! http_obj.started? && ! http_obj.frozen?
http_obj.use_ssl = true
http_obj.verify_mode = OpenSSL::SSL::VERIFY_NONE
if @ca_file
Expand Down

5 comments on commit 88762d4

@haarts
Copy link

@haarts haarts commented on 88762d4 Feb 3, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still experience this error sometimes using the latest version of Mechanize (0.9.0) which includes this fix.
I can’t reproduce this bug in a reliable way but I was thinking maybe the line

http_obj.use_ssl = true

causes the object to freeze. Although I looked in the source of the net/https and did not find any reference to the object being frozen.

@haarts
Copy link

@haarts haarts commented on 88762d4 Feb 3, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still experience this error sometimes using the latest version of Mechanize (0.9.0) which includes this fix.
I can’t reproduce this bug in a reliable way but I was thinking maybe the line

http_obj.use_ssl = true

causes the object to freeze. Although I looked in the source of the net/https and did not find any reference to the object being frozen.

@fastman
Copy link

@fastman fastman commented on 88762d4 Feb 7, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try setting keep_alive to false when initializing Mechanize Agent

@LouisStAmour
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agent.keep_alive = false worked for me, when even updating to 0.9.0 failed after multiple requests. (Like 30 or so of 600)

@vpereira
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agent.keep_alive didnt work for me. IT works in my mac osx but not in CENTOS 5.3

Please sign in to comment.