-
Notifications
You must be signed in to change notification settings - Fork 43
Switch from node.js domains to child process #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… instance of the platform it was initialized to manage
…ssage sent to client without disconnecting the socket.
published to npm: |
First try in Hyperchannel: Everything works now! 🎉 |
Just to document it here: memory usage of the XMPP platform worker process is ~14MB on my machine just now. So that would be about 72 platform instances per GB of memory (not counting inevitable size increase from adding platform features). Depending on how many platforms we want to spin up per Kosmos Chat user, this can quickly add up, of course. But memory is also cheap nowadays. You can get 64GB machines at Hetzner for about 40 EUR/month for example. So I wouldn't worry about this at all for our own infra. But you would obviously hit limits on cheapo cloud VMs much sooner (for people self-hosting for their family or company e.g.). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice implementation! Just added a couple of nitpicks.
packages/sockethub/src/worker.ts
Outdated
import randToken from 'rand-token'; | ||
import Store from 'secure-store-redis'; | ||
import hash from 'object-hash'; | ||
const { fork } = require('child_process'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use an import here, too?
packages/sockethub/src/worker.ts
Outdated
|
||
import crypto from './crypto'; | ||
import services from './services'; | ||
import SharedResources from './shared-resources'; | ||
import config from './config'; | ||
import {platform} from "os"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's always use spaces between curly braces. Should probably be enforced by ESLint at some point soon.
Actually, after reloading Hyperchannel, I wasn't able to connect at all anymore. And it looks like the platform instance isn't terminated, even though the log says so. I can still see the process running, after Sockethub has reported that it terminated it. Edit: I killed the process manually then, and the next connection worked fine again. |
Yeah I'm seeing it as well. This sent me down a path toward considering some modifications to the worker as it might be adding unnecessary complexity after the refactor to processes. I'm not totally sure yet, need to think about it some more. |
…ocess manager and sends jobs to a special id to route to the platform thread
…he queue for jobs
Could you maybe post an update on what the recent commits mean? Would be cool if someone could help out here... |
@galfert thanks for catching these, they are fixed. |
Cool, the second error is gone now. But I'm still seeing the Also, at least for XMPP, when the connection fails (e.g. because of invalid credentials), the whole Sockethub server crashes:
|
@galfert thanks for catching these, can you try again? should be fixed this time. |
Yes, warnings are gone and server doesn't crash anymore on auth failures 👍 I can also connect to both IRC and XMPP at the same time 🎉 Sending messages also works, but the client doesn't seem to receive messages anymore. E.g. the list of users of a room when asking for When sending a message from another IRC client, I can see this in the SH logs:
But in Hyperchannel, I don't see any incoming message. I'm not 100% sure, but I think yesterday I received the room attendance messages at least. Hadn't tried chat messages yet, because of the errors. |
@silverbucket Did you see @galfert's comment? |
Yeah, I saw the comment, and talked with @galfert about it on a call a few weeks ago, I just haven't had any time to sit down and work on anything, but hopefully very soon. |
Alright, got the incoming messages (platform to client direction) working. Things should work fine, but the checkboxes in the PR desc still need to be addressed (or in the case of the 3rd one, decided upon). I will work on 1 & 2 very soon, would love to have some help/suggestions on 3, it's a standard parent/process issue and nothing sockethub specific. |
Yay, I can confirm that I can send and receive messages with Hyperchannel now, in both IRC and XMPP, without problems. Great work! 👍 |
@silverbucket Are those really important to solve in this same PR, instead of smaller, new ones? I don't see anything in the list that seems like a real blocker for us to deploy a potential new master from this for Kosmos Chat. (Merging to |
@skddc the first and second issues (updating changed credentials and handling single-instance platforms) should be fixed as this PR breaks that functionality. The second is almost complete. I will hopefully have time to complete these two issues next week as I'm out of town this weekend. |
Why not just create issues for those and document them as known issues in the README? As long as you don't tag a new release, it won't impact anyone using that functionality at the moment. In fact, kredits naturally incentivizes smaller, more focused PRs (that are easier to review and merge as well), by limiting the largest label to 5000. Smaller PRs also make it much easier to work with more people in parallel, as anyone wanting to use this branch for feature development, would now have to branch off an unstable branch. |
I would also prefer to merge this PR now, because it's working much better than the current master already. Also, I think I would like to give task number 3 (killing the child processes when the main process dies) a try tomorrow. And I would rather create a new PR against master than against this PR. |
Sounds good to me! Going to merge this PR, I created those 3 issues and linked them to a v3.2 project, along with other related issues. Thanks guys for all the help with this! |
Due to issues with some modules when used within a node.js
domain
, I've switched to running the platform activity in it's own child process. This creates an extra layer of abstraction, child processrpc
communication, but overall gives us more security in the safety of the main sockethub thread, while the child processes can be destroyed and restarted whenever we get an uncaught error, or any unexpected behavior.feeds
which one be one generic child process anyone can use, or a persistent platform likexmpp
orirc
which would have a new child process for each user[actor])platform.js
file which is executed for each child process and is responsible for initializing the module and interfacing between it, the job queue, and the parent sockethub process.Some outstanding things to resolve:
updateCredential
messages (when username or password are changed from within a sockethub session, those new credentials need to be updated for that sessions verification process.feeds
) need to verify they are started up correctly and managed efficiently. Some work still needs to be done here.Some other things of note:
This actually fixes another issue where a crashed platform would disconnect the client socket. Additionally, the handling of any failure outside of the context of a job (AS command sent from client) are also reported back to the client as part of the cleanup of that thread. This means that in some cases, the client can receive an error message twice.
In neither case is the client socket disconnected, and the next time a command is sent to that platform a new process will be spawned if it doesn't already exist.