Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Releasing write() callbacks on error #133

Closed
mcollina opened this issue May 20, 2015 · 5 comments
Closed

Releasing write() callbacks on error #133

mcollina opened this issue May 20, 2015 · 5 comments

Comments

@mcollina
Copy link
Member

In case the streams errors, e.g. for a broken TCP socket, or an application error, all buffered write callbacks are never called, here is an example:

var Writable = require('stream').Writable
var inherits = require('util').inherits

function MyWritable (opts) {
  Writable.call(this, opts)
}

inherits(MyWritable, Writable)

MyWritable.prototype._write = function (chunk, enc, done) {
  console.log('_write', chunk.toString())
  setTimeout(function () {
    done(new Error('faulty one'))
  }, 500)
}

var stream = new MyWritable()

stream.write(new Buffer('Hello First'), 'utf8', print('hello'))
stream.write(new Buffer('Hello Second'), 'utf8', print('second'))

stream.on('error', function (err) {
  console.log('error received', err)
})

function print (value, err) {
  return function () {
    console.log('done', value, err)
  }
}

The actual code I am using to fix this behavior is https://github.com/mcollina/aedes/blob/master/lib/client.js#L87-L91.

I spoke to @mafintosh about this one at a couple of conference, so better log it here (and maybe resolve it).

@mcollina
Copy link
Member Author

I am ok to submit a PR on this issue, if you think this should be addressed.

@mcollina
Copy link
Member Author

Or should I resubmit this into the iojs repo?

@mcollina
Copy link
Member Author

Closing and resubmitting to iojs, as it might be the best place to address this anyway.

@kanongil
Copy link

I wanted something like this in node, but for some reason the issue was closed by @chrisdickinson. See nodejs/node-v0.x-archive#5920.

@mcollina
Copy link
Member Author

I reposted on iojs: nodejs/node#1746

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants