spdy-http2 / node-spdy

SPDY server on Node.js
2.8k stars 196 forks source link

Error: write after end and TypeError: Cannot read property 'writeQueueSize' of null #210

Closed gx0r closed 9 years ago

gx0r commented 9 years ago

Hi, I'm getting these errors with spdy-2.0.0 beta4. No erros on spdy 1.32.3.

Error: write after end and TypeError: Cannot read property 'writeQueueSize' of null

node v2.4.0

Stack trace is:

Error: write after end
     at writeAfterEnd (/home/u/testapp/node_modules/spdy/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_writable.js:191:12)
     at Stream.Writable.write (/home/u/testapp/node_modules/spdy/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_writable.js:236:5)
     at Handle.writeEnc (/home/u/testapp/node_modules/spdy/node_modules/handle-thing/lib/handle.js:198:18)
     at Handle.writeBuffer (/home/u/testapp/node_modules/spdy/node_modules/handle-thing/lib/handle.js:226:15)
     at createWriteReq (net.js:701:21)
     at Socket._writeGeneric (net.js:669:11)
     at Socket._write (net.js:692:8)
     at doWrite (_stream_writable.js:292:12)
     at clearBuffer (_stream_writable.js:396:7)
     at onwrite (_stream_writable.js:331:7)
     at Socket.WritableState.onwrite (_stream_writable.js:89:5)
     at WriteWrap.afterWrite (net.js:770:12)
     at /home/u/testapp/node_modules/spdy/node_modules/handle-thing/lib/handle.js:199:11
     at afterWrite (/home/u/testapp/node_modules/spdy/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_writable.js:380:3)
     at onwrite (/home/u/testapp/node_modules/spdy/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_writable.js:371:7)
     at WritableState.onwrite (/home/u/testapp/node_modules/spdy/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_writable.js:116:5)

net.js:679
 if (req.async && this._handle.writeQueueSize != 0)
                              ^
TypeError: Cannot read property 'writeQueueSize' of null
   at Socket._writeGeneric (net.js:679:32)
   at Socket._write (net.js:692:8)
   at doWrite (_stream_writable.js:292:12)
   at clearBuffer (_stream_writable.js:396:7)
   at onwrite (_stream_writable.js:331:7)
   at Socket.WritableState.onwrite (_stream_writable.js:89:5)
   at WriteWrap.afterWrite (net.js:770:12)
   at /home/u/testapp/node_modules/spdy/node_modules/handle-thing/lib/handle.js:199:11
   at afterWrite (/home/u/testapp/node_modules/spdy/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_writable.js:380:3)
   at onwrite (/home/u/testapp/node_modules/spdy/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_writable.js:371:7)
   at WritableState.onwrite (/home/u/testapp/node_modules/spdy/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_writable.js:116:5)
   at doNTCallback0 (node.js:408:9)
   at process._tickCallback (node.js:337:13)

Test case is:

'use strict';
const koa = require('koa');
const app = module.exports = koa();
const spdy = require('spdy');
const fs = require('fs');
const stream = require('stream');
const _ = require('lodash');

const options = {
    servers: [{
        "host": "localhost",
        "port": 28015,
        "db": "test"
    }]
};

const r = require('rethinkdbdash')(options);

const getMessages = function () {
    var first = true;
    var stringifier = new stream.Transform();
    stringifier._writableState.objectMode = true;
    stringifier._transform = function (data, encoding, done) {
        console.log(data);
        if (first) {
            first = false;
            this.push('[');
        } else {
            this.push('\n,')
        }
        this.push(JSON.stringify(data));
        done();
    };

    stringifier._flush = function (done) {
        if (first) {
            this.push('[');
        }
        this.push(']');
        done();
    };

    var query = r.table('messages')

    return query.toStream()
    .pipe(stringifier)
};

app.use(function *(next) {
    this.response.body = getMessages();
})

var credentials;
var privateKey = fs.readFileSync('server.key', 'utf8');
var certificate = fs.readFileSync('server.crt', 'utf8');
credentials = {key: privateKey, cert: certificate};

var server = spdy.createServer(credentials, app.callback());

server.listen(8443);
indutny commented 9 years ago

@llambda thank you for the report! I'm afraid that it is quite hard to do anything with this test case. Is there any way to reduce it to at remove the database dependency?

gx0r commented 9 years ago

@indutny Thanks for taking a look! I was hoping to give a test case without needing RethinkDB, but I wasn't so far able to reproduce it just using a fs.createReadStream, well I didn't have time yet to fully try that and I wanted to open the issue sooner rather than later anyway just in case.

Fortunately though, it's only takes a few seconds to create a new rethinkdb and insert some test data. The data doesn't really matter, just some random JSON. Tonight or next day I can try to make a better test case with just needing a file stream, though I am not 100% sure if it would trigger the issue.

indutny commented 9 years ago

I have just started experiencing this myself on my blog. Will figure it out soon.

indutny commented 9 years ago

This should be fixed in beta6. Sorry I was on different things for all this time!