Git Product home page Git Product logo

Comments (6)

do11 avatar do11 commented on August 28, 2024

I decided to spend some time figuring out your bug. And I think I found root cause:

      def receive_data(data)
        debug [:connection, data]
        processed = @on_data.call(data) if @on_data

        return if processed == :async or processed.nil?
        relay_to_servers(processed)
      end

When on_headers_complete is called inside of on_data callback it calls relay_to_servers() with current value of @buffer (which accumulates current HTTP request), and after that relay_to_servers() is called once again (in receive_data) with the same data that triggered on_headers_complete callback. Thus, last received data is duplicated to backend servers. In my case it's "\r\n" string.

on_data callback in http_proxy.rb example unconditionally returns data, after it's processed, which then is checked for :async or nil. To resolve bug need somehow signal from on_headers_complete callback to on_data to not return data for receive_data.

I decided to fix is like this:

  conn.on_data do |data|
    @buffer << data
    @p << data
    data = nil if @buffer.empty?
    data
  end

You already clear @buffer in on_headers_complete, and setting data to nil would trigger return in your receive_data handler before relay_to_servers() is called. ✌️

from em-proxy.

do11 avatar do11 commented on August 28, 2024

Figuring all this out took 2-3 hours of my life, "thank you" for that.

ps. Also, I wonder why you make @buffer and @p instance variables in your http_proxy.rb example. That is at least confusing, as if this supposed to have any meaning, but it isn't.

from em-proxy.

igrigorik avatar igrigorik commented on August 28, 2024

Right, good catch.. And we should probably also stop appending to @buffer once we've processed the headers. Willing to put together a patch? :)

from em-proxy.

do11 avatar do11 commented on August 28, 2024

No. I think I already did more than wanted.

🏃

from em-proxy.

igrigorik avatar igrigorik commented on August 28, 2024

Ok. Thanks for reporting this.

from em-proxy.

do11 avatar do11 commented on August 28, 2024

Why ticket is closed if bug is not fixed?

from em-proxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.