Comments (3)
Hi @raxoft ,
Thank you for opening this issue.
I'm reading through the code to track the behavior and yes, :enter_master
blocks (or FIO_CALL_IN_MASTER
callbacks) will be called multiple times - once after each time the master process spawns a worker.
The documentation about this might not be clear and I am sorry about that. I think this is mostly a naming and documentation issue.
Anyway, you are right - a subscription created by this block will be inherited by any child process after the first time the block was called.
Is subscription inheritance a feature or a bug?
This is true not only for when starting the server, but also when performing a hot restart (sending a USR1
signal sent to iodine) - than all the (new) workers will inherit all the master processes subscriptions.
This can't be changed without breaking the default subscription inheritance behavior (which arises from the nature of fork
).
Since I'm now rewriting the code (working on version 0.8.x of the core library), I wonder if subscription inheritance is more of a problem than it is a feature and should I find a way for subscribe
to prevent unwanted inheritance... making, perhaps, inheritance explicit.
Workaround
Of your suggested workaround solutions I liked this one the best:
# subscribe in master (called once).
Iodine.subscribe('test') do |source, data|
puts "Process #{Process.pid} (master #{Iodine.master?}) received #{data.inspect}"
end
Iodine.on_state(:enter_child) do
# unsubscribe in child (called only once when spawned).
Iodine.unsubscribe('test')
end
from iodine.
Ah, silly me. You are right, it all makes sense. I knew that the subscription is inherited, so I can't just subscribe at the top level, as that would be inherited to each worker. So I thought if I limit it to the :enter_master
block, it will be called in master only after the workers are spawned. Then later I read that it is called for each worker spawned, but at that point I didn't connect it with the inheritance and that the subsequent forks will inherit the prior subscription. That's why it is n-1, not n. And you are right that even if the block was called only once, the subsequent respawns of future workers would still inherit the subscription...
Well, your suggested solution works fine for me. It's the same thing which one does when plumbing the file descriptors in parent and child process after fork. I should have realized it myself. However, regarding the possible enhancement you mention, you can add a flag which would work similar to FD_CLOEXEC for file descriptors. That's quite handy feature that saves quite a lot of troubles after forking and execing something. In your case it would mean after fork in the child process going through all subscriptions and unsubscribing those which are marked that they should not be inherited. It's essentially what the workaround does, but has the advantage that it doesn't require explicit knowledge of all subscriptions which might exist prior the fork.
In either case, thanks for explaining the behavior and sorry for bothering you. It's all clear now so feel free to close this at any time. Thanks.
from iodine.
Hi @raxoft ,
I'm already working on a solution for the 0.8.x version. Thanks for pointing out this use-case 👍🏻
B.
from iodine.
Related Issues (20)
- Iodine failing to compile with Ruby 3.2.0preview_2 HOT 5
- The future of iodine (vs. plezi)...? HOT 9
- [Rack 3] Response headers with Array value should produce multiple header fields HOT 3
- CPU usage when idle HOT 3
- Iodine.unsubscribe crashes when called with symbol. HOT 4
- unix socket not writeable due umask HOT 8
- Writes to STDOUT even when Iodine.verbosity = 0 HOT 1
- Does not honor HUP signal. HOT 1
- Iodine stops on TERM signal with error when it run with -pid key and more than one worker HOT 1
- The Fixnum is gone as of Ruby-2.4 HOT 3
- response code 418 results in 500 Internal Server Error HOT 1
- [FEAT] return reason for closed connection/client HOT 7
- Static file serving: allow mounting of multiple local dirs HOT 14
- binary C extension not built? HOT 26
- How to get client instance id HOT 3
- ondisconnect example HOT 1
- rage-rb HOT 1
- undefining the allocator of T_DATA class IodineObjectStorage at startup HOT 2
- Iodine failing to build in fedora 40 HOT 5
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 iodine.