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

  • Home
  • SEARCH
  • 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 6977849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:40:41+00:00 2026-05-27T17:40:41+00:00

I’ve written up a minimal example of this. The code is posted here: https://gist.github.com/1524725

  • 0

I’ve written up a minimal example of this. The code is posted here: https://gist.github.com/1524725

I start my server, start my client, verify that the connection between the two is successful, and finally kill the server with CTRL+C. When the server dies, the client immediately runs to completion and closes without printing the message in either on_client_close or on_client_disconnect. There is no perceptible delay.

From the reading I’ve done, because the client process is terminating normally there isn’t any chance that the STDOUT buffer isn’t being flushed.

It may also be worth noting that when I kill the client instead of the server, the server responds as expected, firing the on_ws_disconnect function and removing the client connection from its list of active clients.

32-bit Ubuntu 11.10
Socket.io v0.8.7
Socket.io-client v0.8.7
NodeJS v0.6.0

Thanks!

— EDIT —

Please note that both the client and the server are Node.js processes rather than the conventional web browser client and node.js server.

  • 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-27T17:40:42+00:00Added an answer on May 27, 2026 at 5:40 pm

    NEW ANSWER

    Definitely a bug in io-client. 🙁

    I was able to fix this by modifying socket.io-client/libs/socket.js. Around line 433, I simply moved the this.publish('disconnect', reason); above if (wasConnected) {.

    Socket.prototype.onDisconnect = function (reason) {
        var wasConnected = this.connected;
    
        this.publish('disconnect', reason);
    
        this.connected = false;
        this.connecting = false;
        this.open = false;
    
        if (wasConnected) {
          this.transport.close();
          this.transport.clearTimeouts();
    

    After pressing ctrl+c, the disconnect message fires in roughly ten seconds.

    OLD DISCUSSION

    To notify client of shutdown events, you would add something like this to demo_server.js:

    var logger = io.log;
    
    process.on('uncaughtException', function (err) {
      if( io && io.socket ) {
         io.socket.broadcast.send({type: 'error', msg: err.toString(), stack: err.stack});
      }
      logger.error(err);
      logger.error(err.stack);
    
      //todo should we have some default resetting (restart server?)
      app.close();
      process.exit(-1);
    });
    
    process.on('SIGHUP', function () {
      logger.error('Got SIGHUP signal.');
      if( io && io.socket ) {
         io.socket.broadcast.send({type: 'error', msg: 'server disconnected with SIGHUP'});
      }
      //todo what happens on a sighup??
      //todo if you're using upstart, just call restart node demo_server.js
    });
    
    process.on('SIGTERM', function() {
      logger.error('Shutting down.');
      if( io && io.socket ) {
         io.socket.broadcast.send({type: 'error', msg: 'server disconnected with SIGTERM'});
      }
      app.close();
      process.exit(-1);
    });
    

    Of course, what you send in the broadcast.send(…) (or even which command you use there) depends on your preference and client structure.

    For the client side, you can tell if the server connection is lost using on(‘disconnect’, …), which you have in your example:

    client.on('disconnect', function(data) {
       alert('disconnected from server; reconnecting...');
       // and so on...
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Specifically, suppose I start with the string string =hello \'i am \' me And
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.