J o: Node/cluster/socketio/redis

Beitrag lesen

Guten Morgen,

Ich bin leider absolut mit meinem Latein am Ende und entschuldige mich schonmal dafür das dies etwas länger wird.

Gestern Abend bin ich bei mir auf diesen Fehler gestoßen. (Kurz: Meine installierten versionen von socket.io und socket.io-redis waren nicht kompatible).

Also habe ich meine installierten Packages auf den neusten stand gebracht.

Seit dem passiert es MANCHMAL, dass die erste Verbindung zum Server unterbrochen wird, sprich, das connection Event im io Object feuert 1 oder 2 Mal obwohl bei dem Client die Verbindung nur einmal aufgebaut wird.

Mein Server sieht dabei etwa wie folgt aus:

var port = 31415;
var threads = 1; // require('os').cpus().length;

var http = require('http');
var cluster = require('cluster');

var express = require('express');
var session = require('express-session');
var mongoStore = require('connect-mongo')(session);

var general = require('./functions/server/js/general');

var app = express();

app.use(session({
  secret: 'topSecret',
  resave: false,
  saveUninitialized: true,
  store: new mongoStore({
    url: 'mongodb://localhost:27017'
  })
}));
app.get( '/' , function( req, res ){
  res.sendFile( __dirname + '/index.html' );
});

app.get('/style.css', function(req, res){
  res.sendFile(__dirname + '/style.css');
});
if ( cluster.isMaster ) {
	for ( var i = 0; i < threads; i++ ) cluster.fork();
} else if ( cluster.isWorker ) {
	var server = http.createServer( app );
	var io = require('socket.io').listen( server );
	var ioRedis = require('socket.io-redis');
	io.adapter( ioRedis( { host: 'localhost', port: 6379 } ) );
	server.listen( port );
	io.sockets.on( 'connection', function( socket ){
		
		console.log('socket started ' + socket.id) // feuert mitunter 2 mal
		socket.on('disconnect', function(){
		
			console.log('sockets disconnected ' + socket.id) /* feuert falls in erster Verbindung 		
																											  "irgendetwas" passiert obwohl der 			
																												browser/tab nicht geschlossen wird */
		});
	});
}

Beim Client passiert dann erstmal dies:

function webSocket () {
	var socket = io();
	console.log('start socket') // feuert in jedem Fall nur einmal
}

Um es vorweg zunehmen, es tritt kein Fehler auf, also keine Error nachricht in der Console des Servers.

Nach dem Update ergibt ein neues npm list --depth=0 nun Folgendes (inwieweit vorher Fehler aufgetreten sind kann ich, ehrlich gesagt, nicht mehr sagen):

tes@1.0.0 /var/www/test
├── bcrypt@1.0.3
├── connect-mongo@2.0.1
├── express@4.16.3
├── express-session@1.15.6
├── handlebars@4.0.11
├── mongodb@3.0.4
├── node-cron@1.2.1
├── nodemailer@4.6.2
├── nodemon@1.17.1
├── request-ip@2.0.2
├── socket.io@2.0.4
└── socket.io-redis@5.2.0

npm ERR! missing: hawk@3.1.3, required by node-pre-gyp@0.6.39
npm ERR! missing: mkdirp@0.5.1, required by node-pre-gyp@0.6.39
npm ERR! missing: rimraf@2.6.1, required by node-pre-gyp@0.6.39
npm ERR! missing: tar@2.2.1, required by node-pre-gyp@0.6.39
npm ERR! missing: boom@2.10.1, required by hawk@3.1.3
npm ERR! missing: cryptiles@2.0.5, required by hawk@3.1.3
npm ERR! missing: hoek@2.16.3, required by hawk@3.1.3
npm ERR! missing: sntp@1.0.9, required by hawk@3.1.3
npm ERR! missing: hoek@2.16.3, required by boom@2.10.1
npm ERR! missing: boom@2.10.1, required by cryptiles@2.0.5
npm ERR! missing: hoek@2.16.3, required by sntp@1.0.9
npm ERR! missing: minimist@0.0.8, required by mkdirp@0.5.1
npm ERR! missing: console-control-strings@1.1.0, required by npmlog@4.1.0
npm ERR! missing: readable-stream@2.2.9, required by are-we-there-yet@1.1.4
npm ERR! missing: console-control-strings@1.1.0, required by gauge@2.7.4
npm ERR! missing: string-width@1.0.2, required by gauge@2.7.4
npm ERR! missing: strip-ansi@3.0.1, required by gauge@2.7.4
npm ERR! missing: code-point-at@1.1.0, required by string-width@1.0.2
npm ERR! missing: is-fullwidth-code-point@1.0.0, required by string-width@1.0.2
npm ERR! missing: strip-ansi@3.0.1, required by string-width@1.0.2
npm ERR! missing: number-is-nan@1.0.1, required by is-fullwidth-code-point@1.0.0
npm ERR! missing: ansi-regex@2.1.1, required by strip-ansi@3.0.1
npm ERR! missing: string-width@1.0.2, required by wide-align@1.1.2
npm ERR! missing: combined-stream@1.0.5, required by request@2.81.0
npm ERR! missing: hawk@3.1.3, required by request@2.81.0
npm ERR! missing: mime-types@2.1.15, required by request@2.81.0
npm ERR! missing: safe-buffer@5.0.1, required by request@2.81.0
npm ERR! missing: delayed-stream@1.0.0, required by combined-stream@1.0.5
npm ERR! missing: combined-stream@1.0.5, required by form-data@2.1.4
npm ERR! missing: mime-types@2.1.15, required by form-data@2.1.4
npm ERR! missing: extsprintf@1.0.2, required by jsprim@1.4.0
npm ERR! missing: extsprintf@1.0.2, required by verror@1.3.6
npm ERR! missing: mime-db@1.27.0, required by mime-types@2.1.15
npm ERR! missing: safe-buffer@5.0.1, required by tunnel-agent@0.6.0
npm ERR! missing: glob@7.1.2, required by rimraf@2.6.1
npm ERR! missing: fs.realpath@1.0.0, required by glob@7.1.2
npm ERR! missing: inflight@1.0.6, required by glob@7.1.2
npm ERR! missing: inherits@2.0.3, required by glob@7.1.2
npm ERR! missing: minimatch@3.0.4, required by glob@7.1.2
npm ERR! missing: once@1.4.0, required by glob@7.1.2
npm ERR! missing: path-is-absolute@1.0.1, required by glob@7.1.2
npm ERR! missing: once@1.4.0, required by inflight@1.0.6
npm ERR! missing: wrappy@1.0.2, required by inflight@1.0.6
npm ERR! missing: brace-expansion@1.1.7, required by minimatch@3.0.4
npm ERR! missing: balanced-match@0.4.2, required by brace-expansion@1.1.7
npm ERR! missing: concat-map@0.0.1, required by brace-expansion@1.1.7
npm ERR! missing: block-stream@0.0.9, required by tar@2.2.1
npm ERR! missing: fstream@1.0.11, required by tar@2.2.1
npm ERR! missing: inherits@2.0.3, required by tar@2.2.1
npm ERR! missing: inherits@2.0.3, required by block-stream@0.0.9
npm ERR! missing: graceful-fs@4.1.11, required by fstream@1.0.11
npm ERR! missing: inherits@2.0.3, required by fstream@1.0.11
npm ERR! missing: mkdirp@0.5.1, required by fstream@1.0.11
npm ERR! missing: rimraf@2.6.1, required by fstream@1.0.11
npm ERR! missing: fstream@1.0.11, required by tar-pack@3.4.0
npm ERR! missing: once@1.4.0, required by tar-pack@3.4.0
npm ERR! missing: readable-stream@2.2.9, required by tar-pack@3.4.0
npm ERR! missing: rimraf@2.6.1, required by tar-pack@3.4.0
npm ERR! missing: tar@2.2.1, required by tar-pack@3.4.0
npm ERR! missing: fstream@1.0.11, required by fstream-ignore@1.0.5
npm ERR! missing: inherits@2.0.3, required by fstream-ignore@1.0.5
npm ERR! missing: minimatch@3.0.4, required by fstream-ignore@1.0.5
npm ERR! missing: wrappy@1.0.2, required by once@1.4.0
npm ERR! missing: buffer-shims@1.0.0, required by readable-stream@2.2.9
npm ERR! missing: core-util-is@1.0.2, required by readable-stream@2.2.9
npm ERR! missing: inherits@2.0.3, required by readable-stream@2.2.9
npm ERR! missing: isarray@1.0.0, required by readable-stream@2.2.9
npm ERR! missing: process-nextick-args@1.0.7, required by readable-stream@2.2.9
npm ERR! missing: string_decoder@1.0.1, required by readable-stream@2.2.9
npm ERR! missing: util-deprecate@1.0.2, required by readable-stream@2.2.9
npm ERR! missing: safe-buffer@5.0.1, required by string_decoder@1.0.1

Nun anscheinend läuft da einiges schief, also habe ich gerade nochmal alle module/packages deinstalliert und neu installiert und keine Veränderung der npm ERR!(ors).

Damit bin ich wieder beim Anfang und habe immernoch absolute keine Ahnung wo ein Fehler liegen könnte.

Gruß
Jo