Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@coorpacademy/cluster-sticky
Advanced tools
A simple performant way to use socket.io with recluster, based on Spion's sticky-listen.
This fork was motivated by needs to handle:
npm install @coorpacademy/sticky-listen
In your cluster.js
that uses recluster, use sticky.createBalancer
to create a sticky balancing server.
var recluster = require('recluster'),
path = require('path'),
sticky = require('sticky-listen')
var cluster = recluster(path.join(__dirname, 'server.js'), {
readyWhen: 'ready',
workers: 2 // #cpus, default is require('os').cpus().length
});
cluster.run();
process.on('SIGUSR2', function() {
console.log('Got SIGUSR2, reloading cluster...');
cluster.reload();
});
console.log("spawned cluster, kill -s SIGUSR2", process.pid, "to reload");
// Added for the sticky listener:
var balancer = sticky.createBalancer({
behindProxy: false,
activeWorkers: cluster.activeWorkers,
maxRetries: 5,
retryDelay: 100
});
balancer.listen(8081, function() {
console.log("Sticky balancer listening on port", 8081);
});
In your server.js
, use sticky.listen
instead of server.listen
to start the server,
then use process.send({cmd: 'ready'})
to indicate that the worker is ready.
var sticky = require('sticky-listen');
var server = require('http').createServer(function(req, res) {
res.end('worker: ' + process.env.NODE_WORKER_ID);
});
sticky.listen(server)
process.send({cmd: 'ready'})
This module is based on Spion's sticky-listen but it simplify hash management.
For use from the worker process
Listens for sticky connections from a worker server. The port doesn't need to be specified.
For use from the master process
Creates a new master balancer server that balances between worker servers.
Returns a regular net.Server
. Call server.listen(port) to start listening
for connections and balancing those connections across the cluster.
Sticky sessions are achieved based on the IP address of the client - requests from the same IP are redirected to the same worker index.
The available options are
activeWorkers
A function that returns a hash of the worker slots. For recluster based
balancers that would be cluster.activeWorkers
. The hash should contain:
length
, the number of worker slots that serve requests0..length
, a field that contains a worker object
of a worker that is capable of receiving new connections. If a worker isn't
ready at that slot, the field should be null
retryDelay
If there are no worker available to serve the client, retry finding one after
retryDelay
miliseconds.
maxRetries
The number of retries to attempt before giving up and sending a 502 Bad Gateway error to the client.
behindProxy
If you use this option, sticky-listen will read the headers and look for
x-forwarded-for
when reading the IP address of the client. This enables the
balancer to work well even behind proxies such as HAProxy or nginx.
This software is licensed under the MIT License.
Copyright Fedor Indutny, 2015; Gorgi Kosev, 2015; Loïc Calvy, 2016
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Sticky listener based on Spion 's sticky-listen
The npm package @coorpacademy/cluster-sticky receives a total of 2 weekly downloads. As such, @coorpacademy/cluster-sticky popularity was classified as not popular.
We found that @coorpacademy/cluster-sticky demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.