Skip to content

Issue with ruby 2.4.0 #683

Description

@mightylucene

I am facing following error with ruby 2.4.0, It works fine with 2.3.3

NoMethodError: undefined method `close' for #<StubSocket:0x007f871cf99070>
Did you mean?  closed?
               clone

The line causing is simply a Net::HTTP.post_form

Activity

  1. bblimke commented on Feb 10, 2017

    @bblimke
    Owner

    Interesting. StubSocket does have close method defined.

    Would you mind providing a sample code to reproduce the issue?

  2. jiggneshhgohel commented on Feb 15, 2017

    @jiggneshhgohel

    I am also facing the same error after upgrading Ruby from version 2.3.2 to 2.4.0 in my Rails 5.0.0.1 application. My spec examples fails with the same error:

    Failure/Error: response = http_client.post(json_payload) # json_payload because request's Content-Type is application/json.
          
          NoMethodError:
            undefined method `close' for #<StubSocket:0x0000000c8c3488>
            Did you mean?  closed?
                           clone
    
          # /home/jignesh/.rvm/gems/ruby-2.4.0@my_app-rails-5/gems/webmock-2.1.0/lib/webmock/http_lib_adapters/net_http.rb:125:in `start_without_connect'
          # /home/jignesh/.rvm/gems/ruby-2.4.0@my_app-rails-5/gems/webmock-2.1.0/lib/webmock/http_lib_adapters/net_http.rb:150:in `start'
          # /home/jignesh/.rvm/gems/ruby-2.4.0@my_app-rails-5/gems/rest-client-2.0.0/lib/restclient/request.rb:766:in `transmit'
          # /home/jignesh/.rvm/gems/ruby-2.4.0@my_app-rails-5/gems/rest-client-2.0.0/lib/restclient/request.rb:215:in `execute'
          # /home/jignesh/.rvm/gems/ruby-2.4.0@my_app-rails-5/gems/rest-client-2.0.0/lib/restclient/request.rb:52:in `execute'
          # /home/jignesh/.rvm/gems/ruby-2.4.0@my_app-rails-5/gems/rest-client-2.0.0/lib/restclient/resource.rb:67:in `post'
          # ./app/utils/notifications/notification_mode/push_notification.rb:285:in `send_push_notification_request'
    ...
    ....
    ...
    

    Below is the relevant code-snippet

          def send_push_notification_request(payload)
            begin
              json_payload = payload.to_json
              response = http_client.post(json_payload) # json_payload because request's Content-Type is application/json.
            rescue RestClient::Exception => rce
              response = rce.response
            end
    
            response_status = response.code
            Rails.logger.info "Push Notification Response Status: #{response_status}"
    
            is_push_delivered = (APPERY_PUSH_NOTIFICATION_SEND_API_SUCCESS_STATUS == response_status)
    
            unless is_push_delivered
              response_body = response.body.empty? ? "{}" : response.body
              json_hash = JSON.parse(response_body)
              error_message = json_hash["description"]
              error_code = json_hash["code"]
              Rails.logger.warn(">>>>>>>> Could not deliver push notification to device(uid: #{payload[:filter][:deviceID]}). Appery Push Notification API responded with error: '#{error_message}' and error code: '#{error_code}'")
            end
    
            is_push_delivered
          end
    
          def http_client
            @http_client ||= RestClient::Resource.new(request_url, headers: request_headers)
          end
    

    Hope that helps in reproducing the error and fixing this issue.

  3. bblimke commented on Feb 15, 2017

    @bblimke
    Owner

    @jiggneshhgohel I can see you are using WebMock 2.1.0

    Support for ruby 2.4.0 has been added in WebMock 2.3.1

    @lokenmakwana what version of webmock do you use?

  4. jiggneshhgohel commented on Feb 15, 2017

    @jiggneshhgohel

    @bblimke Thanks for your prompt response. I am updating my gem and will share the spec run results here.

  5. jiggneshhgohel commented on Feb 15, 2017

    @jiggneshhgohel

    @bblimke Updating webmock gem from 2.1.0 to version 2.3.2 fixed the mentioned error in comment #683 (comment).

    Thanks a lot!

  6. mightylucene commented on Feb 15, 2017

    @mightylucene
    Author

    I was also using WebMock 2.1.0 with ruby 2.4

    Just upgraded to WebMock 2.3.2 and everything is fine.

    Thanks

  7. added a commit that references this issue on Apr 9, 2017
  8. added a commit that references this issue on Aug 15, 2018
  9. 13 remaining items

  10. added a commit that references this issue on Apr 1, 2020
  11. added a commit that references this issue on May 1, 2020
  12. added a commit that references this issue on Jun 13, 2020
  13. added a commit that references this issue on Aug 13, 2020
  14. added a commit that references this issue on Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions