Skip to content

undefined method "write" #999

Closed
Closed
@zsan

Description

@zsan

Hello,

Just FYI, i have this error message when i run rspec

(byebug)  fill_in "Password", with: "12345678"
*** NoMethodError Exception: undefined method `write' for #<StubSocket:0x00007fa21298ab28 @closed=true>

webmock's version 3.18.0

Downgraded to 3.17.1 solve the issue

Activity

bblimke

bblimke commented on Aug 18, 2022

@bblimke
Owner

@zsan thank you for reporting.

Are you able to provide an example code to reproduce it or show more stacktrace to understand where this write is called?

Would you mind trying the following two commits and see if it works on any of them?

gem 'webmock', github: 'bblimke/webmock', branch: '102dd56'
gem 'webmock', github: 'bblimke/webmock', branch: '2c10bd9'

@rzane any thoughts?

ingemar

ingemar commented on Aug 18, 2022

@ingemar

I can confirm that 2c10bd9 is the offending commit.

Installing 102dd56 and our test suite runs just fine!

bblimke

bblimke commented on Aug 18, 2022

@bblimke
Owner

I have released 3.18.1 with reverted 2c10bd9

It would be good to get a test or sample code to reproduce the issue or at least a stacktrace from the error.

MothOnMars

MothOnMars commented on Aug 18, 2022

@MothOnMars

@bblimke , I have a test branch that started failing with 3.18.0:
https://github.com/MothOnMars/search-gov/tree/webmock

https://app.circleci.com/pipelines/github/MothOnMars/search-gov/2333/workflows/e2a6416b-7564-4a5b-8ed0-15bb64382a8b

Sample stacktrace:

Traceback (most recent call last):
	14: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/capybara-3.37.1/lib/capybara/selenium/driver.rb:516:in `block in setup_exit_handler'
	13: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/capybara-3.37.1/lib/capybara/selenium/driver.rb:293:in `quit'
	12: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/common/driver.rb:181:in `quit'
	11: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/bridge.rb:186:in `quit'
	10: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/bridge.rb:625:in `execute'
	 9: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
	 8: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/http/default.rb:77:in `request'
	 7: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/http/default.rb:118:in `response_for'
	 6: from /home/circleci/search-gov/vendor/bundle/ruby/2.7.0/gems/webmock-3.18.0/lib/webmock/http_lib_adapters/net_http.rb:84:in `request'
	 5: from /usr/local/lib/ruby/2.7.0/net/http.rb:1492:in `request'
	 4: from /usr/local/lib/ruby/2.7.0/net/http.rb:1519:in `transport_request'
	 3: from /usr/local/lib/ruby/2.7.0/net/http.rb:1519:in `catch'
	 2: from /usr/local/lib/ruby/2.7.0/net/http.rb:1521:in `block in transport_request'
	 1: from /usr/local/lib/ruby/2.7.0/net/http/generic_request.rb:129:in `exec'
/usr/local/lib/ruby/2.7.0/net/http/generic_request.rb:335:in `write_header': undefined method `write' for #<StubSocket:0x0000564298bf50f0 @closed=true> (NoMethodError)
zsan

zsan commented on Aug 18, 2022

@zsan
Author

@zsan thank you for reporting.

Are you able to provide an example code to reproduce it or show more stacktrace to understand where this write is called?

Hello,

I just put webmock in the Gemfile of my Rails's app, then i put require "webmock/rspec" in spec_helper.rb and i have rspec file like this:

require "rails_helper"

RSpec.feature "LoginMethods", type: :feature, js: true do
  before do
    @google_user = create(:user, login_method: "external", provider: "google_oauth2")
    OmniAuth.config.test_mode = true
  end

  scenario "reject internal login" do
    visit new_user_session_path
    byebug
    fill_in "Email", with: @google_user.email
    fill_in "Password", with: @google_user.password
    click_button "Sign in"
    expect(page).to have_content("This account is for login using Google account.")
  end
end

As you can see i put byebug inside scenario and the error is thrown when i type fill_in "Email", with: @google_user.email within byebug's prompt.

Just FYI, the error is gone when i tried with 3.18.1.

ingemar

ingemar commented on Aug 19, 2022

@ingemar

Version 3.18.1 works fine for us! Thank you for your quick work!

rzane

rzane commented on Aug 23, 2022

@rzane
Contributor

Sorry for the trouble everyone. I'll investigate further and try to figure out what went wrong here. The core problem seems to be that StubSocket isn't a very convincing stub of a socket.

mbajur

mbajur commented on Jan 26, 2025

@mbajur

I have the same issue but with the slightly different case. I'm trying to use vite-ruby gem in my Rails app that has a webvalve dependency. Webvalve uses webmock internally on dev env which breaks ruby-vite setup with:

Puma caught this error: undefined method `write' for an instance of StubSocket (NoMethodError)
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/3.3.0/net/http/generic_request.rb:410:in `write_header'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/3.3.0/net/http/generic_request.rb:206:in `exec'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rack-proxy-0.7.7/lib/net_http_hacked.rb:51:in `begin_request_hacked'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rack-proxy-0.7.7/lib/rack/http_streaming_response.rb:52:in `response'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rack-proxy-0.7.7/lib/rack/http_streaming_response.rb:24:in `code'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rack-proxy-0.7.7/lib/rack/proxy.rb:156:in `perform_request'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/vite_ruby-3.9.1/lib/vite_ruby/dev_server_proxy.rb:20:in `perform_request'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rack-proxy-0.7.7/lib/rack/proxy.rb:87:in `call'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.0.8/lib/rails/engine.rb:530:in `call'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.4.2/lib/puma/configuration.rb:272:in `call'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.4.2/lib/puma/request.rb:100:in `block in handle_request'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.4.2/lib/puma/thread_pool.rb:378:in `with_force_shutdown'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.4.2/lib/puma/request.rb:99:in `handle_request'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.4.2/lib/puma/server.rb:464:in `process_client'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.4.2/lib/puma/server.rb:245:in `block in run'
/Users/mbajur/.local/share/mise/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.4.2/lib/puma/thread_pool.rb:155:in `block in spawn_thread'

No matter if I'm on webmock 3.17.1 or 3.18.1 or edge. There are three gems involved in this so I'm not sure if webmock is the one to blame but i will be super grateful for any tips or monkeypatches or just pointing me into the right direction 🙏

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

        Participants

        @bblimke@ingemar@zsan@MothOnMars@mbajur

        Issue actions

          undefined method "write" · Issue #999 · bblimke/webmock