Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined method 'after' for nil #75

Open
jakeonfire opened this issue Feb 21, 2025 · 2 comments
Open

Undefined method 'after' for nil #75

jakeonfire opened this issue Feb 21, 2025 · 2 comments

Comments

@jakeonfire
Copy link

seeing this error in our error tracker. it appears to be related to a recent change introduced in v1.4.0 (11d197f) and is occurring on

interval = @current_selector.after(timeout, callback)
. we are using faraday with the httpx adapter and the fiber-based falcon (https://github.com/socketry/falcon) as our webserver.

stack trace from version 1.4.1:

NoMethodError: undefined method 'after' for nil (NoMethodError)

        interval = @current_selector.after(timeout, callback)
                                    ^^^^^^
  from httpx/connection.rb:907:in `block in HTTPX::Connection#set_request_timeout'
  from httpx/callbacks.rb:12:in `block in HTTPX::Callbacks#once'
  from httpx/callbacks.rb:19:in `block in HTTPX::Callbacks#emit'
  from httpx/callbacks.rb:19:in `delete_if'
  from httpx/callbacks.rb:19:in `emit'
  from httpx/request.rb:274:in `transition'
  from httpx/connection/http1.rb:335:in `block in HTTPX::Connection::HTTP1#handle'
  from httpx/connection/http1.rb:334:in `catch'
  from httpx/connection/http1.rb:334:in `handle'
  from httpx/connection/http1.rb:98:in `block in HTTPX::Connection::HTTP1#consume'
  from httpx/connection/http1.rb:94:in `each'
  from httpx/connection/http1.rb:94:in `each_with_index'
  from httpx/connection/http1.rb:94:in `consume'
  from httpx/connection.rb:403:in `block (2 levels) in HTTPX::Connection#consume'
  from <internal:kernel>:168:in `loop'
  from httpx/connection.rb:399:in `block in HTTPX::Connection#consume'
  from httpx/connection.rb:397:in `catch'
  from httpx/connection.rb:397:in `consume'
  from httpx/connection.rb:245:in `call'
  from httpx/selector.rb:182:in `select_one'
  from httpx/selector.rb:117:in `select'
  from httpx/selector.rb:37:in `block in HTTPX::Selector#next_tick'
  from httpx/selector.rb:29:in `catch'
  from httpx/selector.rb:29:in `next_tick'
  from httpx/session.rb:320:in `block (2 levels) in HTTPX::Session#receive_requests'
  from httpx/session.rb:320:in `catch'
  from httpx/session.rb:320:in `block in HTTPX::Session#receive_requests'
  from <internal:kernel>:168:in `loop'
  from httpx/session.rb:315:in `receive_requests'
  from httpx/session.rb:290:in `send_requests'
  from httpx/session.rb:106:in `request'
  from httpx/adapters/faraday.rb:282:in `block in Faraday::Adapter::HTTPX#connect_and_request'
  from faraday/adapter.rb:45:in `connection'
  from httpx/adapters/faraday.rb:45:in `connect'
  from httpx/adapters/faraday.rb:277:in `connect_and_request'
  from httpx/adapters/faraday.rb:267:in `call'
  from faraday/follow_redirects/middleware.rb:77:in `perform_with_redirection'
  from faraday/follow_redirects/middleware.rb:65:in `call'
  from faraday/rack_builder.rb:152:in `build_response'
  from faraday/connection.rb:452:in `run_request'
  from faraday/connection.rb:200:in `get'
  [...snip]

also seeing:

NoMethodError: undefined method 'each' for nil (NoMethodError)

        @ios.each { |io| io.rewind }
            ^^^^^
  from multipart/post/composite_read_io.rb:73:in `rewind'
  from faraday/multipart/file_part.rb:83:in `each'
  from faraday/multipart/file_part.rb:83:in `rewind'
  from delegate.rb:87:in `method_missing'
  from httpx/request/body.rb:75:in `rewind'
  from httpx/request.rb:245:in `transition'
  from httpx/plugins/retries.rb:114:in `fetch_response'
  from httpx/session.rb:320:in `block in HTTPX::Session#receive_requests'
  from <internal:kernel>:168:in `loop'
  from httpx/session.rb:315:in `receive_requests'
  from httpx/session.rb:290:in `send_requests'
  from httpx/session.rb:106:in `request'
  from httpx/adapters/faraday.rb:282:in `block in Faraday::Adapter::HTTPX#connect_and_request'
  from faraday/adapter.rb:45:in `connection'
  from httpx/adapters/faraday.rb:45:in `connect'
  from httpx/adapters/faraday.rb:277:in `connect_and_request'
  from httpx/adapters/faraday.rb:267:in `call'
  from faraday/follow_redirects/middleware.rb:77:in `perform_with_redirection'
  from faraday/follow_redirects/middleware.rb:65:in `call'
  from faraday/multipart/middleware.rb:27:in `call'
  from faraday/rack_builder.rb:152:in `build_response'
  from faraday/connection.rb:452:in `run_request'
  from faraday/connection.rb:280:in `post'
  [...snip]

downgrading to 1.3.4 resolves the errors.

@jakeonfire
Copy link
Author

jakeonfire commented Feb 21, 2025

might also be worth mentioning we are doing manual, per-host, per-thread faraday connection caching

class Connections
  extend Thread::Local

  def initialize
    @connections = {}
  end

  # @return [Faraday::Connection]
  def get(base_url, request_middleware: nil)
    key = [base_url, request_middleware].join(":")

    @connections[key] ||= Faraday.new(base_url) do |builder|
      # configure connection
    end
  end
end

@HoneyryderChuck
Copy link
Owner

Hi, thanks for the report.

It's a known bug, already reported here. I'm engaged with the original reporter in the process of identifying the correct fix.

If you want to help out, and as per instructions in the thread at the bottom of the originalissue, run the issue-334 branch on your side, collect logs and send them to me for further analysis, do keep the ticket open if you don't have a gitlab account. Otherwise, please close it as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants