visionmedia/nedis — Issue #11: "Socket is not writable" when sending QUIT
Author: tisba
Created: 2012-02-22 18:25:30+00:00
State: open

I discovered a problem, where in out testsuite I'm sending a QUIT (in a test-teardown function) to close the client's connection. If there are outstanding responses from other requests to nedis, you'll see:

Error: Socket is not writable
at Socket._writeOut (net.js:391:11)
at Socket.write (net.js:377:17)
at Connection.bool (./node_modules/nedis/lib/connection.js:152:15)
at Object.expire (./node_modules/nedis/lib/commands/keys.js:27:12)
at Connection.invoke (./node_modules/nedis/lib/connection.js:193:13)
at Connection.parse (./node_modules/nedis/lib/connection.js:395:18)
at Socket. (native)
at Socket.emit (events.js:64:17)
at Socket._onReadable (net.js:672:14)
at IOWatcher.onReadable [as callback] (net.js:177:10)

The problem is, that in connection.js (e.g. https://github.com/visionmedia/nedis/blob/master/lib/connection.js#L152) it is not checked, if the stream is writable or not.

I'd like to supply a patch for this problem, but I'd also like to know how you would like it to be solved. Is it correct to just call a wrapper function that will first check `if (this.stream.writable)` before actually doing `this.stream.write(...)`? Are there any bad tradeoffs I'm not seeing yet?

Best

Sebastian