{"action":"created","issue":{"url":"https://api.github.com/repos/Joris-van-der-Wel/node-pg-large-object/issues/1","labels_url":"https://api.github.com/repos/Joris-van-der-Wel/node-pg-large-object/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/Joris-van-der-Wel/node-pg-large-object/issues/1/comments","events_url":"https://api.github.com/repos/Joris-van-der-Wel/node-pg-large-object/issues/1/events","html_url":"https://github.com/Joris-van-der-Wel/node-pg-large-object/issues/1","id":83999681,"number":1,"title":"uncaughtException: invalid large-object descriptor","user":{"login":"yanickrochon","id":78461,"avatar_url":"https://avatars.githubusercontent.com/u/78461?v=3","gravatar_id":"","url":"https://api.github.com/users/yanickrochon","html_url":"https://github.com/yanickrochon","followers_url":"https://api.github.com/users/yanickrochon/followers","following_url":"https://api.github.com/users/yanickrochon/following{/other_user}","gists_url":"https://api.github.com/users/yanickrochon/gists{/gist_id}","starred_url":"https://api.github.com/users/yanickrochon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yanickrochon/subscriptions","organizations_url":"https://api.github.com/users/yanickrochon/orgs","repos_url":"https://api.github.com/users/yanickrochon/repos","events_url":"https://api.github.com/users/yanickrochon/events{/privacy}","received_events_url":"https://api.github.com/users/yanickrochon/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-02T12:26:03Z","updated_at":"2015-06-02T13:23:17Z","closed_at":"2015-06-02T13:23:17Z","body":"I get an uncaughtException when trying to access more than one large object at once.\r\n\r\nThe app I'm writing is a webservice that's storing larg files into Postgres, then retrieved via secure URLs. The problem is that a browser may request content in parallel, and many browsers can do as well. But, to fix this issue, I'd need to build a queue system. However, is there any way to fix this on this module's end?\r\n\r\n```\r\nerror: uncaughtException: invalid large-object descriptor: 1 \r\n   [ 'Error: invalid large-object descriptor: 1',\r\n     '    at Connection.parseE (/home/xxxxx/dev/vitex/node_modules/pg.js/lib/connection.js:534:11)',\r\n     '    at Connection.parseMessage (/home/xxxxx/dev/vitex/node_modules/pg.js/lib/connection.js:361:17)',\r\n     '    at Socket.<anonymous> (/home/xxxxx/dev/vitex/node_modules/pg.js/lib/connection.js:105:22)',\r\n     '    at Socket.EventEmitter.emit (events.js:107:17)',\r\n     '    at readableAddChunk (_stream_readable.js:159:16)',\r\n     '    at Socket.Readable.push (_stream_readable.js:126:10)',\r\n     '    at TCP.onread (net.js:514:20)' ] }\r\n```"},"comment":{"url":"https://api.github.com/repos/Joris-van-der-Wel/node-pg-large-object/issues/comments/107952008","html_url":"https://github.com/Joris-van-der-Wel/node-pg-large-object/issues/1#issuecomment-107952008","issue_url":"https://api.github.com/repos/Joris-van-der-Wel/node-pg-large-object/issues/1","id":107952008,"user":{"login":"yanickrochon","id":78461,"avatar_url":"https://avatars.githubusercontent.com/u/78461?v=3","gravatar_id":"","url":"https://api.github.com/users/yanickrochon","html_url":"https://github.com/yanickrochon","followers_url":"https://api.github.com/users/yanickrochon/followers","following_url":"https://api.github.com/users/yanickrochon/following{/other_user}","gists_url":"https://api.github.com/users/yanickrochon/gists{/gist_id}","starred_url":"https://api.github.com/users/yanickrochon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yanickrochon/subscriptions","organizations_url":"https://api.github.com/users/yanickrochon/orgs","repos_url":"https://api.github.com/users/yanickrochon/repos","events_url":"https://api.github.com/users/yanickrochon/events{/privacy}","received_events_url":"https://api.github.com/users/yanickrochon/received_events","type":"User","site_admin":false},"created_at":"2015-06-02T13:23:17Z","updated_at":"2015-06-02T13:23:17Z","body":"The app is using `co` and `koa.js` to serve files, and perhaps this the main difference. This is the code I have (it works) : \r\n\r\n```js\r\nvar locks = [];\r\n\r\nvar suspend = require('co-suspend');\r\nvar LargeObjectManager = require('pg-large-object').LargeObjectManager;\r\nvar Connections = require('beyo-model-mapper').Connections;\r\n\r\nfunction * getStream(oid) {\r\n  var marker = suspend();\r\n  var adapter = yield Connections.get(options.adapter);\r\n  var lo = new LargeObjectManager(adapter);\r\n\r\n  if (locks.locked) {\r\n    locks.push(marker);\r\n    yield marker.wait();\r\n  }\r\n\r\n  locks.locked = true;\r\n\r\n  // When working with Large Objects, always use a transaction \r\n  adapter.query('BEGIN', function(err, result) {\r\n    if (err) {\r\n      marker.resume(err);\r\n    } else {\r\n      lo.openAndReadableStream(oid, BUFFER_SIZE, function(err, size, stream) {\r\n        if (err) {\r\n          marker.resume(err);\r\n        } else {\r\n          stream.on('end', function() {\r\n            adapter.query('COMMIT');\r\n\r\n            locks.locked = false;\r\n\r\n            if (locks.length) {\r\n              locks.pop().resume();\r\n            }\r\n          });\r\n\r\n          marker.resume(null, stream);\r\n        }\r\n      });\r\n    }\r\n  });\r\n\r\n  return yield marker.wait();\r\n};\r\n```\r\n\r\nI sometimes forget that not everyone works with yieldables :)\r\n\r\nBut, also this same problem will occur if you ever switch to a Promise/A+ base API."}}