EAGAIN error while using nodejs DNS load balancing + socket.io + socket.io-redis. How can I solve?

Viewed 463

The server periodically opens a text file to add or change content. There was no problem with one server, but after load balancing and using redis to connect the server and two servers to share the folder, EAGAIN error occurs.

There is no problem in connecting multiple clients from Server 1 and referencing the same text file and changing the contents. It is an irregular error when the client of Server 1 and the client of Server 2 refer to the same text file. How can I solve?

++ We found the problem. When sharing a folder with nfs, if the root of the shared folder is server 1, an error EAGAIN on server 1 Conversely, if the root of the shared folder is server 2, an error EAGAIN occurs on server 2. If you set up a shared folder on another server for testing and you connect Server 1 and Server 2 to a shared folder on another server, you do not get an error. Why?

Server Configuration

DNS load balancing 
nodejs(socket.io,socket.io-redis) SERVER 1, 2
redis

npm module version:

express@4.13.4
socket.io@1.5.0
socket.io-redis@1.1.1
socket.io-adapter@0.5.0
fs@0.0.1
multer@0.1.8

js file:

var express = require('express');
var multer = require('multer');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var mysql = require('mysql');
var fs = require('fs');  
var request = require("request");
var fcm = new FCM(apiKey);

var redis  = require('socket.io-redis');
io.adapter(redis({host:'xxxxxxxxxxxx',port:xxxx}));


http.listen(port, function(){
  console.log('listening1 on *:'+port);
});

io.sockets.on('connection', function(socket){


    socket.on('setchat', function(data){

        var obj=JSON.parse(data);
        var txtfile = fs.readFileSync('./room/'+obj.roomid+".txt", 'utf8');     
                ... 
                ...
                ...
                ...
    });

    socket.on('getcount', function(data){
            var txtfile = fs.readFileSync('./room/'+data+".txt", 'utf8');

            var chatRoom=JSON.parse(txtfile);
            var strChatroom = JSON.stringify(chatRoom); 

            fs.open('./room/'+data+".txt", 'w', function(err, fd) {

            if(err) throw err;
                var buf = new Buffer(strChatroom);

                fs.write(fd, buf, 0, buf.length, null, function(err, written, buffer) {
                    if(err) throw err;
                        fs.close(fd, function() {
                            console.log('getcount Done');
                        });
                });

        });

    });


});

error code:

Error: EAGAIN: resource temporarily unavailable, open './room/chattingtext.txt
    at Error (native)

chattingtext.txt:

{"totalmember":{"id":"name","id":"name"},"nowmember":["name"],"msginfo":[{"index":1,"user":"name","message":"asdasd","count":0,"date":"13:45"}]}
0 Answers
Related