Comments (15)
Yes I suggested to Maria that she adds intrinsic
to OTP and it became significant
instead. It's a better version of it.
from ranch.
I think it's because you stop the worker process with the reason normal
, try shutdown
or {shutdown, Reason}
instead.
from ranch.
That doesn't make a difference. In my case the proto_worker
is a gen_stamem
and I verified that when I stop with {stop, shutdown}
terminate()
is called with reason shutdown
. However, that has no influence on the supervisor. In the OTP supervisor
documentation is says, that a supervisor is usually stopped by its parent. So shouldn't it be then the responsibility of connection_sup
to terminate proto_sup
or at least offer an API for it?
from ranch.
You probably need to set the restart rates as well, in RabbitMQ they are 0/1 https://github.com/rabbitmq/rabbitmq-server/blob/master/deps/rabbit/src/rabbit_connection_sup.erl#L66
You basically want to force the supervisor to stop when the process holding the socket exits. As you can see there we have a second supervisor containing other child processes which may restart independently.
from ranch.
OK, I see. RabbitMQ uses a custom supervisor implementation that adds a new worker type intrinsic
that causes the supervisor to exit when the worker exits normally. When I try it with the OTP supervisor, I can get the supervisor to exit when I set the intensity to 0 and the type to permanent
but that existing is reported as an error (as intended by OTP).
Is the use case of connection_type = supervisor
with a OTP supervisor
so rare? Shouldn't it be possible without a custom supervisor?
I've the feeling I'm still missing something here...
from ranch.
I think it's the first time it comes up. I've only used it with Cowboy which has its own "supervisor" and RabbitMQ which has one of the "supervisor2" that is patched from OTP. To be honest we should probably seek to contribute this intrinsic type back to OTP. Putting it on the list. :-)
from ranch.
But what would speak against letting connection_sup
stop the proto_sup
on request?
from ranch.
To be honest we should probably seek to contribute this intrinsic type back to OTP.
So... a supervisor that exits when the (last) child exits? I haven't looked at RabbitMQs supervisor2
, but I think that would be useful 🥰
from ranch.
Yes it is indeed useful.
But what would speak against letting
connection_sup
stop theproto_sup
on request?
If I'm understanding correctly you're asking about Ranch stopping the supervisor when the process holding the socket exits? At the moment Ranch is only aware of the supervisor, I don't think we want to make Ranch aware of more processes than it supervises directly (outside of the socket control handshake).
You can most likely have the supervisor contain a second child that would do just that, by the way, detect the connection is gone and stop the parent (the supervisor). I don't think there's a huge need to have this in Ranch.
from ranch.
Sure, but my point is, that from the pure OTP perspective, the only process than can stop a supervisor is the supervisor's supervisor, which is the connection_sup
process in ranch. I don't think ranch needs to detect that the connection is gone. But only offer a function in connection_sup
to stop a child, like the OTP supervisor
does. Then, whatever process detects that the connection is gone can call that function of connection_sup
to stop its supervisor.
It's more like the problem wouldn't exist if connection_sup
would conform to OTPs supervisors
(or at least offer this one function).
from ranch.
I am pretty sure you can just call sys:terminate/2,3
to stop your supervisor. The thing about the parent only applies to exit signals. I do not think we need another function in Ranch for doing this.
from ranch.
AFAIK sys:terminate/2,3
will terminate the supervisor before it has the chance to gracefully stop all its child processes. This is probably OK to call in terminate/3
of the first process with an one_for_all
strategy.
I tried to add a terminate_child
to ranch_conns_sup
but didn't found a satisfactory and clean way of doing it, so no PR from my side...
I'll probably stick to the modified supervisor method. Having the option to stop a supervisor when a specific process exists might become handy in the future.
from ranch.
sys:terminate
does normal termination, it's the same as if the parent was terminating it, except perhaps the terminate reason might differ.
from ranch.
OK, my fault. My worker was not set up to trap existing signals.
So maybe the sys:terminate/3
solution is the easiest one.
from ranch.
w.r.t. intrinsic
, OTP-24 adds the concept of "significant" children. See https://erlang.org/doc/man/supervisor.html#significant_child; I assume it's essentially the same thing.
from ranch.
Related Issues (20)
- 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 17
- 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
- Minor: ranch_ssl:listen can return non-atom error reasons HOT 2
- Restart issues found when upgrading 1.8 -> 2.1.0 HOT 8
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.