Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Uncaught Error: no writecb in Transform class #318

Closed
haadcode opened this issue Jun 8, 2016 · 5 comments
Closed

Uncaught Error: no writecb in Transform class #318

haadcode opened this issue Jun 8, 2016 · 5 comments
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@haadcode
Copy link
Member

haadcode commented Jun 8, 2016

Came across the following error while running tests for orbit-db.

It happens on .files.add, using the following:

ipfs.files.add(new Buffer(JSON.stringify(defaultNetwork), 'utf-8'), (err, res) => ...)

It happens always. However, if I don't call ipfs.goOnline() at init, the error doesn't occur.

ipfs v0.13.0

Uncaught Error: no writecb in Transform class
      at afterTransform (node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:74:40)
      at TransformState.afterTransform (node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:58:12)
      at node_modules/ipfs/lib/core/ipfs/files.js:90:11
      at node_modules/ipfs-merkle-dag/lib/dag-service.js:68:16
      at done (node_modules/ipfs-bitswap/lib/index.js:198:9)
      at node_modules/ipfs-bitswap/lib/index.js:205:9
      at finish (node_modules/ipfs-bitswap/lib/index.js:263:11)
      at node_modules/ipfs-bitswap/lib/index.js:290:17
      at BufferList._callback (node_modules/ipfs-repo/lib/stores/datastore.js:60:9)
      at BufferList.end (node_modules/bl/bl.js:98:10)
      at ReadStream.onend (_stream_readable.js:498:10)
      at endReadableNT (_stream_readable.js:913:12)
@haadcode haadcode added the kind/bug A bug in existing code (including security flaws) label Jun 8, 2016
@haadcode
Copy link
Member Author

haadcode commented Jun 8, 2016

Also, this is pretty much a blocker as it happens every time and prevents js-ipfs to run smoothly.

@dignifiedquire
Copy link
Member

interesting, not seen before

@haadcode
Copy link
Member Author

haadcode commented Jun 8, 2016

Repro case: https://github.com/haadcode/orbit-db/tree/latest-js-ipfs (run npm i && npm test)

If you leave out the goOnline here https://github.com/haadcode/orbit-db/blob/latest-js-ipfs/test/counterdb.test.js#L46, the tests pass.

@hackergrrl
Copy link
Contributor

I did some digging into this.

The symptom (writecb) happens when the callback in a Transform stream gets called multiple times. In ipfs.files.add in js-ipfs we add each file to the repo, and then ask the DAG Service to find each file that we just added. This takes us down into DAGService, then BlockService, and finally Bitswap.

It looks like there's a race condition in js-ipfs-bitswap in the case that the underlying block datastore takes a long time to do a put and there are two getBlocks pending for that same block. getBlock will call finish if its attempt to get the block succeeds or it gets a notification that the block has become available. However, if both happen, then the callback gets called twice.

I filed a PR (ipfs/js-ipfs-bitswap#20) and confirmed that it fixes your error. 🎉

@daviddias
Copy link
Member

daviddias commented Aug 15, 2016

@haadcode can you confirm the error no longer exists? Closing, reopen if necessary

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug A bug in existing code (including security flaws)
Projects
None yet
Development

No branches or pull requests

4 participants