{"action":"created","issue":{"url":"https://api.github.com/repos/coopernurse/node-pool/issues/147","repository_url":"https://api.github.com/repos/coopernurse/node-pool","labels_url":"https://api.github.com/repos/coopernurse/node-pool/issues/147/labels{/name}","comments_url":"https://api.github.com/repos/coopernurse/node-pool/issues/147/comments","events_url":"https://api.github.com/repos/coopernurse/node-pool/issues/147/events","html_url":"https://github.com/coopernurse/node-pool/issues/147","id":169003999,"number":147,"title":"Process exits with waiting clients ","user":{"login":"olalonde","id":416585,"avatar_url":"https://avatars.githubusercontent.com/u/416585?v=3","gravatar_id":"","url":"https://api.github.com/users/olalonde","html_url":"https://github.com/olalonde","followers_url":"https://api.github.com/users/olalonde/followers","following_url":"https://api.github.com/users/olalonde/following{/other_user}","gists_url":"https://api.github.com/users/olalonde/gists{/gist_id}","starred_url":"https://api.github.com/users/olalonde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olalonde/subscriptions","organizations_url":"https://api.github.com/users/olalonde/orgs","repos_url":"https://api.github.com/users/olalonde/repos","events_url":"https://api.github.com/users/olalonde/events{/privacy}","received_events_url":"https://api.github.com/users/olalonde/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/coopernurse/node-pool/labels/bug","name":"bug","color":"eb6420"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-02T22:27:35Z","updated_at":"2016-09-18T10:47:43Z","closed_at":"2016-09-18T10:47:43Z","body":"```javascript\r\nconst pool = initPidPool({ max: 1 })\r\n\r\nconst handleError = (err) => {\r\n  console.error(err)\r\n  console.error(err.stack)\r\n  process.exit(1)\r\n}\r\n\r\nfor (let i = 0; i < 2; i++) {\r\n  pool.acquire((err, pid) => {\r\n    if (err) return handleError(err)\r\n    console.log(pool.waitingClientsCount())\r\n    console.log(pid)\r\n  })\r\n}\r\n```\r\n\r\nPrints the following and exits:\r\n\r\n```bash\r\n$ babel-node test/pid-pool.js\r\n  loc:main dispense() clients=1 available=0 +0ms info\r\n  loc:main createResource() - creating obj - count=1 min=0 max=1 +2ms verbose\r\n  loc:apiclient:request:1 GET http://localhost/getpid +2ms\r\n  loc:main dispense() clients=2 available=0 +1ms info\r\n  loc:apiclient:request:1 try 1 +122ms\r\n1\r\nm6Myjs4ip6Hm_wLOC88ui-Dx9Ct2\r\n```\r\n\r\nHere's the code for initPidPool:\r\n\r\n```javascript\r\nimport { Pool } from 'generic-pool'\r\n\r\nimport debug from '../utils/debug'\r\n\r\nimport fetchPid from './fetch-pid'\r\n\r\nexport default ({ max = 10 } = {}) => {\r\n  const pidExpiry = {}\r\n  const isExpired = (pid) => Date.now() > pidExpiry[pid]\r\n\r\n  const maxLifespanMillis = 10 * 60 * 1000 // 10min\r\n\r\n  const pool = new Pool({\r\n    max,\r\n    name: 'pid',\r\n    create: (cb) => {\r\n      fetchPid()\r\n        .then((pid) => {\r\n          pidExpiry[pid] = Date.now() + maxLifespanMillis\r\n          cb(null, pid)\r\n        })\r\n        .catch(cb)\r\n    },\r\n    validate: (pid) => !isExpired(pid),\r\n    destroy: (pid) => { debug(`destroy pid ${pid}`) },\r\n    min: 0,\r\n    refreshIdle: false,\r\n    log: debug,\r\n  })\r\n  return pool\r\n}\r\n```\r\n\r\nThe expected behaviour would be for the process to hang indefinitely since max is 1 and the second call to acquire should wait forever since we are not releasing the resource."},"comment":{"url":"https://api.github.com/repos/coopernurse/node-pool/issues/comments/247840581","html_url":"https://github.com/coopernurse/node-pool/issues/147#issuecomment-247840581","issue_url":"https://api.github.com/repos/coopernurse/node-pool/issues/147","id":247840581,"user":{"login":"sandfox","id":260919,"avatar_url":"https://avatars.githubusercontent.com/u/260919?v=3","gravatar_id":"","url":"https://api.github.com/users/sandfox","html_url":"https://github.com/sandfox","followers_url":"https://api.github.com/users/sandfox/followers","following_url":"https://api.github.com/users/sandfox/following{/other_user}","gists_url":"https://api.github.com/users/sandfox/gists{/gist_id}","starred_url":"https://api.github.com/users/sandfox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sandfox/subscriptions","organizations_url":"https://api.github.com/users/sandfox/orgs","repos_url":"https://api.github.com/users/sandfox/repos","events_url":"https://api.github.com/users/sandfox/events{/privacy}","received_events_url":"https://api.github.com/users/sandfox/received_events","type":"User","site_admin":false},"created_at":"2016-09-18T10:47:43Z","updated_at":"2016-09-18T10:47:43Z","body":"@olalonde I've got a bit lost down the rabbit hole that was dealing with the timing/order bugs in the existing version of generic-pool. In a slight acceptance of defeat I wrote v3 to use promises instead  and rewrote alot of the internal logic, and I think I've made the above situation harder to get into (or at least easier to not be in!)\r\nv3 is still alpha but it's on npm `npm install generic-pool@latest`. There are some other additions I want to make but the current API should be what finally ships (unless it's horribly broken).\r\n"}}
{"actor":{"display_login":"sandfox"}}