2015-07-21 167 views
6

錯誤的含義是什麼?節點JS Mysql PROTOCOL ENQUEUE致命錯誤

此代碼適用於我的測試文件。

function handleDisconnect() { 
    objConn = mysql.createConnection(db_config); // Recreate the connection, since 
                // the old one cannot be reused. 
    objConn.connect(function(err) {     // The server is either down 
     if(err) {         // or restarting (takes a while sometimes). 
      console.log('error when connecting to db:', err.code); 
      setTimeout(handleDisconnect, 2000);  // We introduce a delay before attempting to reconnect, 
     }else{ 
      console.log('Connected to db!'); 
     }           // 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. 
    objConn.on('error', function(err) { 
     if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually 
      handleDisconnect();      // lost due to either server restart, or a 
     }else{ 
      throw err; 
     } 
    }); 
} 

handleDisconnect(); 
megaLoop(); 

function megaLoop(){ 
    objConn.query('SELECT u.`email` FROM `users` as u', function(err, rows) { 
     console.log(err); 
     console.log(rows); 
    }); 
    setTimeout(megaLoop, 100); 
} 

但是,當我在我的快速應用程序中使用函數,我得到的錯誤。

{ [Error: Cannot enqueue Query after fatal error.] code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', fatal: false } 

所以,我有什麼劑量錯誤的意思是什麼?和方式劑量它在我的測試工作,而不是我的應用程序?

+0

請訪問回答類似的問題http://stackoverflow.com/a/38418562/543087 – user5858

回答