{"action":"created","issue":{"url":"https://api.github.com/repos/mysqljs/mysql/issues/1473","repository_url":"https://api.github.com/repos/mysqljs/mysql","labels_url":"https://api.github.com/repos/mysqljs/mysql/issues/1473/labels{/name}","comments_url":"https://api.github.com/repos/mysqljs/mysql/issues/1473/comments","events_url":"https://api.github.com/repos/mysqljs/mysql/issues/1473/events","html_url":"https://github.com/mysqljs/mysql/issues/1473","id":165967922,"number":1473,"title":"ConnectionPool leaking","user":{"login":"NasserAlmanji","id":1848549,"avatar_url":"https://avatars.githubusercontent.com/u/1848549?v=3","gravatar_id":"","url":"https://api.github.com/users/NasserAlmanji","html_url":"https://github.com/NasserAlmanji","followers_url":"https://api.github.com/users/NasserAlmanji/followers","following_url":"https://api.github.com/users/NasserAlmanji/following{/other_user}","gists_url":"https://api.github.com/users/NasserAlmanji/gists{/gist_id}","starred_url":"https://api.github.com/users/NasserAlmanji/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NasserAlmanji/subscriptions","organizations_url":"https://api.github.com/users/NasserAlmanji/orgs","repos_url":"https://api.github.com/users/NasserAlmanji/repos","events_url":"https://api.github.com/users/NasserAlmanji/events{/privacy}","received_events_url":"https://api.github.com/users/NasserAlmanji/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-17T09:03:49Z","updated_at":"2016-11-03T02:44:42Z","closed_at":null,"body":"Hi \n\nI had previously opened issue #1425  but it is now closed.\n\nI still have the question of why does new queries cannot be executed because it is waiting for the pool to release a connection\n\nattaching the code,\n\n``` js\n\"use strict\";\n\n\nvar mysql        = require(\"mysql\");\nvar _            = require(\"underscore\");\nvar util         = require(\"util\");\nvar EventEmitter = require(\"events\").EventEmitter;\n\n\nfunction SQLStore(config) {\n\n    this.wpool  = null;\n    this.rpool  = null;\n    this.config = config;\n\n    let self = this;\n    this.pool = mysql.createPool(config);\n    this.pool.on(\"connection\", function (connection) {\n        connection.query(\"use muscat\");\n        connection.query(\"SET SESSION auto_increment_increment=1\");         \n        self.queryFormat(connection);\n        self.emit(\"connection\");        \n    });\n\n    this.pool.on(\"enqueue\", function () {\n        self.emit(\"enqueue\");\n    });\n}\n\n\nutil.inherits(SQLStore, EventEmitter);\n\n\nSQLStore.prototype.queryFormat = function(connection) {\n    if(connection.config.queryFormat) {\n        return;\n    }   \n    connection.config.queryFormat = function(query, values) {\n        if(!values) return query;\n        return query.replace(/\\:(\\w+)/g, function(txt, key) {\n            if(values.hasOwnProperty(key)) {\n                return this.escape(values[key]);\n            }\n            return txt;\n        }.bind(this));\n    };\n};\n\n\nSQLStore.prototype.execute = function(pool, query, info, release, callback) {\n\n    var self = this;\n\n    if((_.isFunction(release)) && (callback === undefined)) {\n        callback = release;\n        //release = true;\n    }\n    else if(typeof callback === \"undefined\") {\n        callback = function() {};\n    }\n\n    pool.getConnection(function(err, connection) {\n        if(err) {\n            if(connection) {\n                connection.release();\n            }\n            self.emit(\"error\", err);\n            callback(err);\n            return;\n        }\n\n        // self.queryFormat(connection);\n        connection.query(query, info, function(query_error, result) {\n            //if(releaseTrue) {\n            connection.release();\n            //}\n\n            if(query_error) {\n                self.emit(\"error\", query_error);\n            }\n            callback(query_error, result);//, connection);\n        });\n\n    });\n};\n\n\nSQLStore.prototype.write = function(query, info, release, callback) {\n\n    // var pool = this.pool.of(\"MASTER-01\");\n    this.execute(this.pool, query, info, release, callback);\n};\n\n\nSQLStore.prototype.read = function(query, info, release, callback) {\n\n    // var pool = this.pool.of(\"SLAVE-01\");\n    this.execute(this.pool, query, info, release, callback);\n};\n\nmodule.exports = SQLStore;\n\n```\n\nand the pool events\n\n``` js\nvar sqlStore = new store(config);\n\n\nsqlStore.on(\"error\", function(error) {\n    //system.error(\"[DB][SQL]\", error);\n    console.log(\"[DB][SQL] Error \", error);\n});\n\n\nsqlStore.on(\"connection\", function() {\n    //system.info(\"[DB][SQL] Connected.\");\n    console.log(\"[DB][SQL] Connected\");\n});\n\n\nsqlStore.on(\"enqueue\", function(data1, data2) {\n    console.log(\"[DB][SQL] Waiting for available connection.\",);\n});\n\n```\n\nThanks for the module\nNasser\n"},"comment":{"url":"https://api.github.com/repos/mysqljs/mysql/issues/comments/258053910","html_url":"https://github.com/mysqljs/mysql/issues/1473#issuecomment-258053910","issue_url":"https://api.github.com/repos/mysqljs/mysql/issues/1473","id":258053910,"user":{"login":"dougwilson","id":67512,"avatar_url":"https://avatars.githubusercontent.com/u/67512?v=3","gravatar_id":"","url":"https://api.github.com/users/dougwilson","html_url":"https://github.com/dougwilson","followers_url":"https://api.github.com/users/dougwilson/followers","following_url":"https://api.github.com/users/dougwilson/following{/other_user}","gists_url":"https://api.github.com/users/dougwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/dougwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougwilson/subscriptions","organizations_url":"https://api.github.com/users/dougwilson/orgs","repos_url":"https://api.github.com/users/dougwilson/repos","events_url":"https://api.github.com/users/dougwilson/events{/privacy}","received_events_url":"https://api.github.com/users/dougwilson/received_events","type":"User","site_admin":false},"created_at":"2016-11-03T02:44:42Z","updated_at":"2016-11-03T02:44:42Z","body":"Hi @NasserAlmanji I'm' very sorry your issue here has been overlooked. I read your question above and looked at your code, but I'm not 100% sure what the question is."}}
{"actor":{"display_login":"dougwilson"}}