{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/knex/issues/960","labels_url":"https://api.github.com/repos/tgriesser/knex/issues/960/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/knex/issues/960/comments","events_url":"https://api.github.com/repos/tgriesser/knex/issues/960/events","html_url":"https://github.com/tgriesser/knex/issues/960","id":104309155,"number":960,"title":"Connection pool depletion ","user":{"login":"matthewsquire","id":11779045,"avatar_url":"https://avatars.githubusercontent.com/u/11779045?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewsquire","html_url":"https://github.com/matthewsquire","followers_url":"https://api.github.com/users/matthewsquire/followers","following_url":"https://api.github.com/users/matthewsquire/following{/other_user}","gists_url":"https://api.github.com/users/matthewsquire/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewsquire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewsquire/subscriptions","organizations_url":"https://api.github.com/users/matthewsquire/orgs","repos_url":"https://api.github.com/users/matthewsquire/repos","events_url":"https://api.github.com/users/matthewsquire/events{/privacy}","received_events_url":"https://api.github.com/users/matthewsquire/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-01T16:49:08Z","updated_at":"2015-09-01T19:58:09Z","closed_at":"2015-09-01T19:58:09Z","body":"I'm using knex on ubuntu/mysql and hitting issue where the connection pool seems to deplete after some number of hours/days.   After looking thru the debug logs, I can find transactions that start but never finish.  All of these (non-completing) transactions seem to start after another transaction is committed but before its connection is released.  Ie the logs look like:\r\n```\r\nMon, 31 Aug 2015 18:31:48 GMT knex:query select found_rows() as numRows\r\nMon, 31 Aug 2015 18:31:48 GMT knex:query COMMIT;\r\nMon, 31 Aug 2015 18:31:48 GMT knex:tx trx780: Starting top level transaction\r\nMon, 31 Aug 2015 18:31:48 GMT knex:client acquiring connection from pool: __knexUid759\r\nMon, 31 Aug 2015 18:31:48 GMT knex:query BEGIN;\r\nMon, 31 Aug 2015 18:31:48 GMT knex:tx trx779: releasing connection\r\nMon, 31 Aug 2015 18:31:48 GMT knex:client releasing connection to pool: __knexUid714\r\n```\r\nAnd transaction trx780 never appears in the logs again.  In all cases that I've found (thus far) where a new top level transaction is started after a `COMMIT` but before a `releasing connection` (according to the logs), that new top level transaction just disappears from the logs and is never finished.  \r\n\r\nAnd after finding 10 of these occurrences in the logs, requests for new connections seem to just hang, where we get a log message for \r\n```\r\nknex:tx trx1293: Starting top level transaction\r\n```\r\nbut then it just hangs (indefinitely) waiting for a connection.   So it seems like the connection is taken by the earlier transactions and never returned, and eventually they all disappear. \r\n\r\nMy actual transaction code isn't all that complicated \r\n```\r\nknex.transaction( function( trx ) {\r\n    cmd.transacting(trx).then(function( rows ) {\r\n        rows.forEach( thisobj.knexGetPerRowFn );\r\n        console.log('knexGet: rows:' + JSON.stringify( rows ) );\r\n        knex.raw('select found_rows() as numRows').transacting( trx )\r\n          .then(function(resp) { \r\n            var numRows = resp[0][0].numRows;\r\n            var listParameters = { totalRows: numRows, limit: parseInt(reserved.limit), offset: parseInt(reserved.offset) };\r\n            trx.commit( rows );\r\n            return returnFn( { status: 'OK', listInfo: listParameters, objects: c3rx.addUrls( rows ) } );\r\n          })\r\n          .catch( function( err ) { \r\n            console.error('Error in knexGet.rows:' + err ); \r\n            trx.rollback( err );\r\n            return returnFn( { status: 'OK', objects: c3rx.addUrls( rows ) } ); // return without listInfo\r\n          } );\r\n       })\r\n      .catch(  function(error) { \r\n        console.error('Error in knexGet:' + error ); \r\n        trx.rollback( error );\r\n        return returnFn( { status: 'ERROR', message: error } ); \r\n      } );\r\n    })\r\n    .then( function(resp) {\r\n      console.error('knexGet completed tx' ); \r\n    })\r\n    .catch( function( err ) {\r\n      console.error('Error in knexGet tx:' + err ); \r\n    })\r\n```\r\nIs this something I'm doing wrong, or is there some kind of timing issue in the connection pool acquisition/release?   \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/tgriesser/knex/issues/comments/136841569","html_url":"https://github.com/tgriesser/knex/issues/960#issuecomment-136841569","issue_url":"https://api.github.com/repos/tgriesser/knex/issues/960","id":136841569,"user":{"login":"matthewsquire","id":11779045,"avatar_url":"https://avatars.githubusercontent.com/u/11779045?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewsquire","html_url":"https://github.com/matthewsquire","followers_url":"https://api.github.com/users/matthewsquire/followers","following_url":"https://api.github.com/users/matthewsquire/following{/other_user}","gists_url":"https://api.github.com/users/matthewsquire/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewsquire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewsquire/subscriptions","organizations_url":"https://api.github.com/users/matthewsquire/orgs","repos_url":"https://api.github.com/users/matthewsquire/repos","events_url":"https://api.github.com/users/matthewsquire/events{/privacy}","received_events_url":"https://api.github.com/users/matthewsquire/received_events","type":"User","site_admin":false},"created_at":"2015-09-01T19:58:09Z","updated_at":"2015-09-01T19:58:09Z","body":"I found an issue in another block of code that was hacked in on the side to use the same connection pool.  Issue on our end."}}