Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7019311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:09:59+00:00 2026-05-27T23:09:59+00:00

My socket server below works fine for 3-4 days, but after dat I get

  • 0

My socket server below works fine for 3-4 days, but after dat I get notifications from Munin that it’s outside specified CPU range (160). Sounds to me like memory isn’t free:d correctly, but I can’t find where?

var io = require('socket.io').listen(80);
var Memcached = require('memcached');
var md5 = require('MD5');
var memcached = new Memcached(['IP']);
var interval_time = 5000;

loglevel = process.argv[2];
if(loglevel == "") loglevel = 1;

io.enable('browser client minification');  // send minified client
io.enable('browser client etag');          // apply etag caching logic based on version number
io.enable('browser client gzip');          // gzip the file

io.sockets.on('connection', function (socket)
{
     socket.on('get_notifications', function (data)
     {
         // verify authorization
        if(data.key == 'XXXXXXX')
        {
            socket.user_id = data.user_id;

            setInterval(function()
            { 
                memcached.get(["ntf_" + socket.user_id, "nnt_" + socket.user_id], function(error, mem_result)
                {
                    num_orders = mem_result['ntf_' + socket.user_id];
                    is_searching = mem_result['nnt_' + socket.user_id];

                    if(typeof(socket.prev_notification)==='undefined') socket.prev_notification = {};

                    var notification = socket.prev_notification;
                    var have_new_notifications = false;

                    if(is_searching != socket.prev_notification.nnt)
                    {
                        have_new_notifications = true;
                        notification.nnt = is_searching;
                    }

                    if(num_orders != socket.prev_notification.ntf)
                    {
                        have_new_notifications = true;
                        notification.ntf = num_orders;
                    }

                    if(have_new_notifications)
                    {
                        var today=new Date();
                        var h=today.getHours();
                        var m=today.getMinutes();
                        var s=today.getSeconds();

                        console.log(h+":"+m+":"+s+' - sending notification to ' + data.user_id);
                        console.log(notification);

                        socket.emit('notifications', notification);
                        socket.prev_notification = notification;
                    }
                });
            }, interval_time); // interval
        }
    });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:09:59+00:00Added an answer on May 27, 2026 at 11:09 pm

    I think the problem is that you fire setInterval every time get_notification event is fired. These intervals never stop working once they started.

    You should write some code which will stop those intervals when certain conditions are met (timeout? client disconnect? whatever). Or change setInterval to setTimeout which will fire itself unless exception is thrown (like for example cannot send data to disconnected client).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a application that I made, server accepts socket connection from clients and do
I'm getting the following exception for the code included below that. This works fine
The code below is creating a server to communicate with clients.This code works fine
I've got a socket server running (it's something that's basically like a chat server).
I am developing a socket server where a client will be bound after being
I'm trying to implement a socket server that will run in most shared PHP
I'm looking for a python socket server framework - not to handle http, but
I'm currently trying to implement a socket server that enables the clients to send
I have to create an sample code that connect to a socket server, and
my application sends file to server using (socket tcp c#) the file transfer works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.