Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

sticky-session

Sticky session balancer based on a `cluster` module

Subscribe to updates I use sticky-session


Statistics on sticky-session

Number of watchers on Github 773
Number of open issues 24
Average time to close an issue about 2 months
Main language JavaScript
Average time to merge a PR about 9 hours
Open pull requests 6+
Closed pull requests 8+
Last commit over 3 years ago
Repo Created over 7 years ago
Repo Last Updated over 1 year ago
Size 68 KB
Organization / Authorindutny
Contributors5
Page Updated
Do you use sticky-session? Leave a review!
View open issues (24)
View sticky-session activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating sticky-session for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Sticky session

A simple performant way to use socket.io with a cluster.

Installation

npm install sticky-session

Usage

var cluster = require('cluster'); // Only required if you want the worker id
var sticky = require('sticky-session');

var server = require('http').createServer(function(req, res) {
  res.end('worker: ' + cluster.worker.id);
});

if (!sticky.listen(server, 3000)) {
  // Master code
  server.once('listening', function() {
    console.log('server started on 3000 port');
  });
} else {
  // Worker code
}

Simple

Reasoning

Socket.io is doing multiple requests to perform handshake and establish connection with a client. With a cluster those requests may arrive to different workers, which will break handshake protocol.

Sticky-sessions module is balancing requests using their IP address. Thus client will always connect to same worker server, and socket.io will work as expected, but on multiple processes!

Note about node version

sticky-session requires node to be at least 0.12.0 because it relies on net.createServer's pauseOnConnect flag.

A deeper, step-by-step explanation on how this works can be found in elad/node-cluster-socket.io

LICENSE

This software is licensed under the MIT License.

Copyright Fedor Indutny, 2015.

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.

sticky-session open issues Ask a question     (View All Issues)
  • almost 3 years Custom ip
  • almost 3 years process.send / master.on("message" not work
  • over 3 years Constantly Connecting/Disconnecting with socket connection.
  • almost 4 years Improve the example usage in README
  • almost 4 years Load balancing
  • almost 4 years About the example code
  • about 4 years Using sticky-session with hapi.js
  • over 4 years node v0.11.15+ should use pauseOnConnect option with net.createServer
  • over 4 years Running two or more http servers with different ports
  • over 4 years Using with another cluster module?
  • over 4 years sticky-session: worker died error TypeError: Cannot call method 'removeListener' of undefined
  • over 4 years At the time of execution of the sudden appearance of an error
  • about 5 years Sticky-Session not working in IE and FireFox
  • over 5 years Need some help using
  • over 5 years IP pool configuration by ISP results issue
  • over 5 years Is remoteAddress going to always be the same for applications behind a proxy?
sticky-session open pull requests (View All Pulls)
  • fixed #37 Problem with newrelic
  • Reverse proxy support
  • Support of Layer 4 Hash Balancing, fixes several issues and supporting reverse proxy ips
  • Added Reverse Proxy Support
  • Hosts & Accessible Server Instance (and tests)
  • fixed respawn
sticky-session questions on Stackoverflow (View All Questions)
  • Socket.io 1.x clustering without sticky session?
  • Amazon ELB - Sticky session lost of cookie
  • NGINX sticky session from request body
  • Socket.io 'Handshake' failing with cluster and sticky-session
  • Angular app breaks load balancing with sticky session
  • NodeJS Socket.io Sticky-Session missing headers
  • Enabling sticky session mode for Apache/Tomcat load balancing
  • Sticky session not working with multiple apache vhosts and multiple JBoss 7.2 server-groups
  • pm2 not listening on the specific port with sticky-session
  • Apache / using header for sticky session
  • Sticky Session for Rest API Calls
  • Setting up Sticky Session on AWS ELB for Prestashop
  • scaling meteorjs applications that are "always on" / sticky session load balancing
  • Azure Web App and sticky session with Affinity Cookie – Reliable?
  • Apache 2.4 switching sessions in sticky session mode even when primary session tomcat is not down
  • Does NodeJS recluster module maintains sticky session
  • Spring Session In Paas Sticky Session
  • How to use sticky-session with cluster in express - node js
  • Using Replicated Cache vs LB sticky session
  • sticky session with apache web server and tomcat servers
  • Is it possible to disable sticky session/ IP affinity?
  • Can session replication takes place without sticky session?
  • Sticky Session mode not working correctly for process taking long time
  • CodeIgniter Session breaks on non-sticky-session load balanced server
  • Pros and Cons of Sticky Session / Session Affinity load blancing strategy?
  • HAProxy with SSL (https) and Sticky Session
  • Session Invalidated in JBOSS clustered environment with load balancer and sticky session
  • Apache LoadBalancing, sticky session, and Spring security framework
  • How to enable Sticky Session in WSO2 Elastic Load Balancer for Vaadin
  • How to check if IIS use sticky session?
sticky-session list of languages used
Other projects in JavaScript