Giter Site home page Giter Site logo

Comments (18)

essen avatar essen commented on May 25, 2024

Yeah, we should probably just drop these connections indeed.

from ranch.

essen avatar essen commented on May 25, 2024

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.

essen avatar essen commented on May 25, 2024

@jinnipark I need more details. Please see previous comment. Thanks!

from ranch.

jinnipark avatar jinnipark commented on May 25, 2024

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.

essen avatar essen commented on May 25, 2024

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.

jinnipark avatar jinnipark commented on May 25, 2024

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.

essen avatar essen commented on May 25, 2024

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.

jinnipark avatar jinnipark commented on May 25, 2024

I'm using R15B01 and without any suvervisor2. I don't even know what it is.

  1. Just downloaded otp source and followed 'configure; make; make install'.
  2. Started a tcp echo server in ranch with a little bit of logging code.
  3. Ran a load generator from a different machine that just repeated connect/disconnect simultaneous 50k clients as best as it could.
  4. After 20 minutes or so, the load generator couldn't connect any more.
  5. Couldn't find any listener with netstat -lt.
  6. 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.
  7. Still reproducible. Never survives longer than 1 hour.
  8. No such failure after the patch.

from ranch.

essen avatar essen commented on May 25, 2024

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.

essen avatar essen commented on May 25, 2024

But before I do that, can I see the source for the protocol you are using?

from ranch.

jinnipark avatar jinnipark commented on May 25, 2024

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.

essen avatar essen commented on May 25, 2024

I am talking about the server not the client. What's the module that Ranch uses for the protocol?

from ranch.

jinnipark avatar jinnipark commented on May 25, 2024

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.

essen avatar essen commented on May 25, 2024

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.

essen avatar essen commented on May 25, 2024

Hm the above patch isn't good actually, this doesn't close the socket. Needs to close the socket.

from ranch.

jinnipark avatar jinnipark commented on May 25, 2024

Thank you. I'll wait for your update.

from ranch.

essen avatar essen commented on May 25, 2024

Would you like to do it?

from ranch.

essen avatar essen commented on May 25, 2024

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)

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.