Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
update dependencies and patch for racing condition
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Apr 24, 2016
1 parent 2cf6f1f commit 78e754e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test/repo-just-for-test*

test/test-repo-for-*
# Logs
logs
*.log
Expand Down Expand Up @@ -35,4 +35,4 @@ node_modules
.node_repl_history

lib
dist
dist
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"fs-blob-store": "^5.2.1",
"idb-plus-blob-store": "^1.0.0",
"ipfs-repo": "^0.6.1",
"idb-plus-blob-store": "^1.1.1",
"ipfs-repo": "^0.6.6",
"lodash": "^4.8.2",
"ncp": "^2.0.0",
"pre-commit": "^1.1.2",
Expand All @@ -60,4 +60,4 @@
"Stephen Whitmore <[email protected]>",
"dignifiedquire <[email protected]>"
]
}
}
22 changes: 21 additions & 1 deletion src/block-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,32 @@ function BlockService (ipfsRepo, exchange) {
let done = false

ws.write(block.data)

ws.once('error', (err) => {
done = true
callback(err)
})

ws.once('finish', () => {
if (!done) callback()
if (!done) {
// Important to note: Writing to a stream
// isn't an atomic process, because streams can be
// piped, and the finish of one only represents that
// the data was buffered to the next one.
// This is something known and 'accepted' on the
// streams API, however, since we expose a callback
// interface on BlockService and a streams one,
// the users will expect for the callback to be fired
// when the final write was concluded. We add a
// timeout to ensure that.
// TODO: Create an elegant way to understand when
// the block was actually flushed to disk. This
// means changing how the blob-stores and repo are
// implemented.
// One option, is polling till we check it
// is written.
setTimeout(callback, 150)
}
})
ws.end()
}
Expand Down
2 changes: 1 addition & 1 deletion test/block-service-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = (repo) => {
})

it('store and get a block, with custom extension', (done) => {
const b = new Block('A random data block', 'ext')
const b = new Block('A random data block 2', 'ext')
bs.addBlock(b, (err) => {
expect(err).to.not.exist
bs.getBlock(b.key, 'ext', (err, block) => {
Expand Down

0 comments on commit 78e754e

Please sign in to comment.