Comments (6)
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.
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.
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.
No. I think I already did more than wanted.
🏃
from em-proxy.
Ok. Thanks for reporting this.
from em-proxy.
Why ticket is closed if bug is not fixed?
from em-proxy.
Related Issues (20)
- NoMethodError: undefined method `on_headers_complete=' for #<Http::NativeParser HOT 5
- Balancing sample doesn't seem to give a new server for every request HOT 2
- Early binding for proxy port HOT 4
- Spec: duplex TCP traffic to two backends google & yahoo is hanging HOT 2
- Can't proxy to pow's domains HOT 3
- Add support for proxying unix domain sockets (JRuby) HOT 6
- Backend selection based on sub-domain HOT 1
- No eventmachine 1.0 support? HOT 4
- On SIGINT foreman throws an error HOT 1
- Skip proxying and just send a response HOT 1
- Select backend on request data HOT 2
- Error HOT 1
- http_proxy.rb -- invalid request URI HOT 3
- http_proxy.rb -- breaking proxy request by adding/duplicating data #52 HOT 2
- Can not re-open issue #52
- Missing licence in rubygems.org
- Missing LICENSE file in rubygem HOT 1
- Syntax error in examples/http_proxy.rb HOT 1
- 2 network HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from em-proxy.