{"action":"created","issue":{"url":"https://api.github.com/repos/tobinbradley/dirt-simple-postgis-http-api/issues/14","repository_url":"https://api.github.com/repos/tobinbradley/dirt-simple-postgis-http-api","labels_url":"https://api.github.com/repos/tobinbradley/dirt-simple-postgis-http-api/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/tobinbradley/dirt-simple-postgis-http-api/issues/14/comments","events_url":"https://api.github.com/repos/tobinbradley/dirt-simple-postgis-http-api/issues/14/events","html_url":"https://github.com/tobinbradley/dirt-simple-postgis-http-api/issues/14","id":272126206,"number":14,"title":"WARNING: Creating a duplicate database object for the same connection","user":{"login":"nbulaj","id":1443426,"avatar_url":"https://avatars2.githubusercontent.com/u/1443426?v=4","gravatar_id":"","url":"https://api.github.com/users/nbulaj","html_url":"https://github.com/nbulaj","followers_url":"https://api.github.com/users/nbulaj/followers","following_url":"https://api.github.com/users/nbulaj/following{/other_user}","gists_url":"https://api.github.com/users/nbulaj/gists{/gist_id}","starred_url":"https://api.github.com/users/nbulaj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nbulaj/subscriptions","organizations_url":"https://api.github.com/users/nbulaj/orgs","repos_url":"https://api.github.com/users/nbulaj/repos","events_url":"https://api.github.com/users/nbulaj/events{/privacy}","received_events_url":"https://api.github.com/users/nbulaj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-11-08T09:16:42Z","updated_at":"2017-11-08T16:24:58Z","closed_at":null,"author_association":"NONE","body":"Hi. I see next warning while using `dirt-simple-postgis-http-api`:\r\n\r\n> WARNING: Creating a duplicate database object for the same connection.\r\n>     at handler (/home/bulai/projects/dirt-simple-postgis-http-api/routes/mvt_v1.js:73:18)\r\n>     at Object.internals.handler (/home/bulai/projects/dirt-simple-postgis-http-api/node_modules/hapi/lib/handler.js:96:36)\r\n>     at request._protect.run (/home/bulai/projects/dirt-simple-postgis-http-api/node_modules/hapi/lib/handler.js:30:23)\r\n>     at internals.Protect.run (/home/bulai/projects/dirt-simple-postgis-http-api/node_modules/hapi/lib/protect.js:64:5)\r\n>     at exports.execute (/home/bulaj/projects/dirt-simple-postgis-http-api/node_modules/hapi/lib/handler.js:24:22)\r\n>     at each (/home/bulai/projects/dirt-simple-postgis-http-api/node_modules/hapi/lib/request.js:383:16)\r\n\r\nI took a look at the [routes/mvt_v1.js](https://github.com/tobinbradley/dirt-simple-postgis-http-api/blob/master/routes/mvt_v1.js#L73) and saw that it initialize a DB connection everytime handler called. I think it can be placed somewhere at the top to prevent memory leaks and in order to optimize the speed of the server."},"comment":{"url":"https://api.github.com/repos/tobinbradley/dirt-simple-postgis-http-api/issues/comments/342871261","html_url":"https://github.com/tobinbradley/dirt-simple-postgis-http-api/issues/14#issuecomment-342871261","issue_url":"https://api.github.com/repos/tobinbradley/dirt-simple-postgis-http-api/issues/14","id":342871261,"user":{"login":"tobinbradley","id":1250538,"avatar_url":"https://avatars1.githubusercontent.com/u/1250538?v=4","gravatar_id":"","url":"https://api.github.com/users/tobinbradley","html_url":"https://github.com/tobinbradley","followers_url":"https://api.github.com/users/tobinbradley/followers","following_url":"https://api.github.com/users/tobinbradley/following{/other_user}","gists_url":"https://api.github.com/users/tobinbradley/gists{/gist_id}","starred_url":"https://api.github.com/users/tobinbradley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tobinbradley/subscriptions","organizations_url":"https://api.github.com/users/tobinbradley/orgs","repos_url":"https://api.github.com/users/tobinbradley/repos","events_url":"https://api.github.com/users/tobinbradley/events{/privacy}","received_events_url":"https://api.github.com/users/tobinbradley/received_events","type":"User","site_admin":false},"created_at":"2017-11-08T16:24:58Z","updated_at":"2017-11-08T16:24:58Z","author_association":"OWNER","body":"Yep. That's something I need to fix. \r\n\r\nIt is where it is currently because it was previously using pg for database connections. It was a performance vs stability issue. Creating a single connection on app load reduces connection creation overhead and it makes the number of Postgres connections more predictable. \r\n\r\nOn the other hand, if using a single pooled connection and it ever goes bad - database server restarted, session idle connection is terminated by the server, network blip, etc. - as far as I can tell, with pg, you're screwed.\r\n\r\nBut I switched it to pg-promise which uses lazy connections - only the actual query methods acquire and release the connection automatically. That should eliminate pg's dead connection issue, and it's why they recommend creating only one global/shared db object per connection (and give a warning if you don't).\r\n\r\nIt's on my todo list. :) "}}
{"actor":{"display_login":"tobinbradley"}}