Comments (18)
Yeah, we should probably just drop these connections indeed.
from ranch.
Hm where did you see an {error, overload}
? Also I'm not sure I can do anything about it? This is the supervisor doing that. Could you provide me with more details?
from ranch.
@jinnipark I need more details. Please see previous comment. Thanks!
from ranch.
Please find the patch below:
--- src/ranch_acceptor.erl +++ src/ranch_acceptor.erl @@ -52,14 +52,20 @@ loop(LSocket, Transport, Protocol, MaxConns, Opts, ListenerPid, ConnsSup) -> MaxConns, Opts, ListenerPid, ConnsSup); %% Found my sockets! {accept, CSocket} -> - {ok, ConnPid} = supervisor:start_child(ConnsSup, - [ListenerPid, CSocket, Transport, Protocol, Opts]), - Transport:controlling_process(CSocket, ConnPid), - ConnPid ! {shoot, ListenerPid}, - NbConns = ranch_listener:add_connection(ListenerPid, ConnPid), - {ok, MaxConns2} = maybe_wait(ListenerPid, MaxConns, NbConns), - ?MODULE:init(LSocket, Transport, Protocol, - MaxConns2, Opts, ListenerPid, ConnsSup); + case supervisor:start_child(ConnsSup, + [ListenerPid, CSocket, Transport, Protocol, Opts]) of + {ok, ConnPid} -> + Transport:controlling_process(CSocket, ConnPid), + ConnPid ! {shoot, ListenerPid}, + NbConns = ranch_listener:add_connection(ListenerPid, ConnPid), + {ok, MaxConns2} = maybe_wait(ListenerPid, MaxConns, NbConns), + ?MODULE:init(LSocket, Transport, Protocol, + MaxConns2, Opts, ListenerPid, ConnsSup); + Error -> + fubar_log:error(?MODULE, [Error]), + ?MODULE:loop(LSocket, Transport, Protocol, + MaxConns, Opts, ListenerPid, ConnsSup) + end; %% Upgrade the max number of connections allowed concurrently. {set_max_conns, MaxConns2} -> ?MODULE:loop(LSocket, Transport, Protocol,
I took this from version 9fd9294.
from ranch.
Yes, I get that, but the only errors supervisor:start_child/2
may return in the case of a simple_one_for_one
supervisor is process start failure which is due to the protocol process failing to start. I'm not sure why it would? Can you explain?
from ranch.
What I observed is not well documented in the erlang reference. The child process itself is ok as it starts and runs ok usually. {error, overload} is an error from the supervisor itself, so it must be handled I guess. When I run my server without this patch and apply very severe load - I mean connect/disconnect/reconnect -, after some time there is no listener any more.
from ranch.
I looked at the source and there is no mention of any {error, overload}
anywhere in the Erlang source. What version are you using? Are you sure you are not using for example supervisor2.erl
which may have added this "feature"?
from ranch.
I'm using R15B01 and without any suvervisor2. I don't even know what it is.
- Just downloaded otp source and followed 'configure; make; make install'.
- Started a tcp echo server in ranch with a little bit of logging code.
- Ran a load generator from a different machine that just repeated connect/disconnect simultaneous 50k clients as best as it could.
- After 20 minutes or so, the load generator couldn't connect any more.
- Couldn't find any listener with netstat -lt.
- Did rb to check error logs stored with log_mf_h and found {error, overload} with the source code reference which was ranch_acceptor line 55.
- Still reproducible. Never survives longer than 1 hour.
- No such failure after the patch.
from ranch.
Alright. Let me ask on the mailing list where this error could come from. I need to understand where it's coming from. I would match on {error, overload}
directly however, to avoid hiding user errors in the protocol start_link function.
from ranch.
But before I do that, can I see the source for the protocol you are using?
from ranch.
I do only server programming and the load generator is not mine but a QA agent's that I don't have the code myself.
I'll prepare my own and try reproducing the error with it.
from ranch.
I am talking about the server not the client. What's the module that Ranch uses for the protocol?
from ranch.
Oh, my...
You're right.
I've been returning {error, overload} in one of my protocol handlers actually.
Sorry.
But still I don't want the error return in handler to stop the listener though.
from ranch.
This could be a feature added to Ranch, to avoid creating a protocol process if the service is overloaded. The above patch would be good except instead of Error
we want to match on {error, overload}
and it needs to be added to the guide and have a test.
from ranch.
Hm the above patch isn't good actually, this doesn't close the socket. Needs to close the socket.
from ranch.
Thank you. I'll wait for your update.
from ranch.
Would you like to do it?
from ranch.
In the current code from last night, if you return anything other than {ok, Pid} then the supervisor ignores what you returned and no process is created. I believe that fixes this!
Closing, thanks.
from ranch.
Related Issues (20)
- Add more Concuerror tests
- How can gen_tcp be configured to support both IPv4 and IPv6 connections HOT 4
- Supervisor protocol process cannot be stopped when connection is closed (connection_type=supervisor). HOT 15
- Upgrading from 1.4 to 2.0 HOT 5
- Release Ranch 1.8 that is compatible with OTP-24 HOT 15
- Ranch 1.7, issues upgrading a tcp to ssl/tls connection HOT 7
- Add hex metadata to Ranch master HOT 1
- Add a function that converts from ProxyInfo to ssl:connection_information/1 return value HOT 2
- using gen_tcp new interface inet_backend socket cann't listen multiple sockets in one port HOT 6
- remove the socket file before the listen and change_mode the socket file right after listen HOT 14
- Update appup for 2.1.0 HOT 3
- Proxy protocol unique ID TLV type HOT 1
- The user guide links on the README are broken HOT 1
- Password should be blanked instead of logged on error HOT 1
- TLS 1.3 connection with client verification always successful HOT 1
- ranch:handshake(Ref) silently drops invalid TLS connections in ranch_ssl via exit(normal) HOT 16
- Questions about "gen_tcp:accept/2" and "num_acceptors" HOT 2
- ranch:stop_listener/1 throws error HOT 2
- {error, no_cert} with `certs_keys` from OTP 25 HOT 8
- Issue when using DTLS HOT 6
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 ranch.