Skip to content

PROTOCOL_CONNECTION_LOST  #1353

@lcherukuri

Description

@lcherukuri

I used below error handling code for connection timeout. Still i face the problem. Did any one faced this problem

var config = require('../config/config');

    module.exports = function(){

        var mysql      = require('mysql');
        var db_config = {
            host     : config.db_host,
            user     : config.db_username,
            password : config.db_password,
            database : config.db_name
        };

        var connection;

        function handleDisconnect() {
              connection = mysql.createConnection(db_config); // Recreate the connection, since

              connection.connect(function(err) {              
                if(err) {                                    
                  console.log('error when connecting to db:', err);
                  setTimeout(handleDisconnect, 2000); 
                }                                   
              });                                   

              connection.on('error', function(err) {
                console.log('db error', err);
                if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
                  handleDisconnect();                        
                } else {                                     
                  throw err;                                 
                }
              });
            }

            handleDisconnect();

        return connection;

    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions