• 27-11-2014, 09:03:00
    #1
    Üyeliği durduruldu
    Merhaba arkadaşlar,
    Node.js ile yazdığım bir server yazılımında bir süre sonra şu hatayı
    almaya başladım ve ne olduğunu tam amlamadım yardımcı olabilirseniz sevinirim.

    Error: Connection lost: The server closed the connection.
    at Protocol.end (/nodejs/node_modules/mysql/lib/protocol/Protocol.js:103:13)
    at Socket.<anonymous> (/nodejs/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

    Burada demek istediği bir süre sonra mysql bağlantıyımı kesiyor acaba?
  • 10-04-2015, 09:52:27
    #2
    Selamlar bayraktar,
    Cevabim gec gelmis olabilir, ama eger baska arkadaslar da bu hatayla karsilasirsa....en azindan deneyebilen bir cozum gorucekler:

    handleDisconnect();-de problem olmali...kodunuzda onun nerde oldugunu bulup, bunu yazmalisiniz:

    var db_config = {
      host: 'localhost',
        user: 'root',
        password: '',
        database: 'example'
    };
    
    var connection;
    
    function handleDisconnect() {
      connection = mysql.createConnection(db_config); // Recreate the connection, since
                                                      // the old one cannot be reused.
    
      connection.connect(function(err) {              // The server is either down
        if(err) {                                     // or restarting (takes a while sometimes).
          console.log('error when connecting to db:', err);
          setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect,
        }                                     // to avoid a hot loop, and to allow our node script to
      });                                     // process asynchronous requests in the meantime.
                                              // If you're also serving http, display a 503 error.
      connection.on('error', function(err) {
        console.log('db error', err);
        if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
          handleDisconnect();                         // lost due to either server restart, or a
        } else {                                      // connnection idle timeout (the wait_timeout
          throw err;                                  // server variable configures this)
        }
      });
    }
    
    handleDisconnect();