spdy-http2 / node-spdy

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

Assertion Error when serving static files with Express #244

Closed motss closed 8 years ago

motss commented 8 years ago

Can it serve static files coupled with Express 4? I encountered Assertion Error when refreshing the page. However no such issue when using Node's own HTTPS.

require('https') => serving static files without any issues. require('spdy') => AssertionError.

assert.js:89
  throw new assert.AssertionError({
  ^
AssertionError: false == true
    at PriorityNode.removeChild (/home/motss/wotss/serve-static/node_modules/spdy-transport/lib/spdy-transport/priority.js:71:3)
    at PriorityNode.remove (/home/motss/wotss/serve-static/node_modules/spdy-transport/lib/spdy-transport/priority.js:60:15)
    at PriorityTree.add (/home/motss/wotss/serve-static/node_modules/spdy-transport/lib/spdy-transport/priority.js:153:23)
    at Stream._initPriority (/home/motss/wotss/serve-static/node_modules/spdy-transport/lib/spdy-transport/stream.js:101:25)
    at new Stream (/home/motss/wotss/serve-static/node_modules/spdy-transport/lib/spdy-transport/stream.js:75:8)
    at Connection._createStream (/home/motss/wotss/serve-static/node_modules/spdy-transport/lib/spdy-transport/connection.js:392:16)
    at Connection._handleHeaders (/home/motss/wotss/serve-static/node_modules/spdy-transport/lib/spdy-transport/connection.js:439:21)
    at Connection._handleFrame (/home/motss/wotss/serve-static/node_modules/spdy-transport/lib/spdy-transport/connection.js:322:10)
    at Parser.<anonymous> (/home/motss/wotss/serve-static/node_modules/spdy-transport/lib/spdy-transport/connection.js:161:10)
    at emitOne (events.js:77:13)
indutny commented 8 years ago

This seems to be a bug. May I ask you to reproduce the issue with server running with DEBUG="spdy*" environment variable and gist the logs? I would like to take a look at them.

indutny commented 8 years ago

Thank you for reporting this.

motss commented 8 years ago

Not sure how much information is needed but I just grabbed as much as I could. And starting at line 199 is where I refresh the page and at the end of the operation I got the assertion error which you can see at the end of the log.

https://gist.github.com/motss/670faf619b02c37098ec

erictsangx commented 8 years ago

+1 if keep refreshing the browser. I am using koa. Briefly inspect the variables, I found the error occurs when child.tree.count > 100(maxCount?)

indutny commented 8 years ago

@motss thank you for that gist. May I ask you to grab all information from the start? It should be enough to run it in DEBUG="spdy:priority" to reduce amount of actual data.

Thank you!

indutny commented 8 years ago

@erictsangx yeah, I think it is definitely caused by this somehow...

indutny commented 8 years ago

@motss nevermind, I know what's causing this.

indutny commented 8 years ago

Should be fixed now, please run npm update. Sorry about the error!

erictsangx commented 8 years ago

Unfortunately, I am using v3.2.0, but the problem still occurs:

debug('hit maximum remove id=%d', this.list[0].id);
this.list.shift().remove();
 -> this.parent.removeChild(this);
    -> var index = utils.binarySearch(this.children.list, child, compareChildren);

It is still caused by returning index=-1

indutny commented 8 years ago

@erictsangx what about spdy-transport which version are you using? (It can be found in npm ls output)

erictsangx commented 8 years ago

@indutny

├─┬ spdy@3.2.0
│ ├── handle-thing@1.2.4
│ ├── http-deceiver@1.2.4
│ ├── select-hose@2.0.0
│ └─┬ spdy-transport@2.0.10
│   ├── hpack.js@2.1.4
│   ├── obuf@1.1.1
│   ├─┬ readable-stream@2.0.5
│   │ ├── core-util-is@1.0.2
│   │ ├── process-nextick-args@1.0.6
│   │ ├── string_decoder@0.10.31
│   │ └── util-deprecate@1.0.2
│   └─┬ wbuf@1.7.1
│     └── minimalistic-assert@1.0.0
indutny commented 8 years ago

@erictsangx may I ask you to run it with DEBUG="spdy:priority" environment variable and post all data as a gist (up to the crash).

motss commented 8 years ago

@erictsangx It's fixed for my case. Thanks a lot!

erictsangx commented 8 years ago

@indutny https://gist.github.com/erictsangx/01a9826b9ad445e03b5f

I am using a for loop generating push streams to push js files when a user requests index.html.

...
res.end(html);
if (res.push) {
    for (let key of pushMapping.keys()) {
        let stream = res.push(key, {
            request: {
                accept: '*/*'
            },
            response: {
                'content-type': 'application/javascript'
            }
        });
        stream.end(pushMapping.get(key));
    }
}
...
motss commented 8 years ago

@erictsangx May I know how to push files while user is requesting index.html?

erictsangx commented 8 years ago

@motss A example from the documentation:

spdy.createServer(options, function(req, res) {
  var stream = res.push('/main.js', {
    request: {
      accept: '*/*'
    },
    response: {
      'content-type': 'application/javascript'
    }
  });
  stream.on('error', function() {
  });
  stream.end('alert("hello from push stream!");'); //main.js content (You can use fs to read js files)

  res.end('<script src="/main.js"></script>'); //index.html content
}).listen(3000);
heavyskyl commented 7 years ago

Have same issue. Have latest libraries versions.

spdy:priority add node=195 parent=0 weight=256 exclusive=1 +36ms spdy:priority hit maximum remove id=1 +0ms spdy:priority add node=197 parent=195 weight=147 exclusive=1 +2ms spdy:priority hit maximum remove id=2 +0ms

{ AssertionError: false == true at PriorityNode.removeChild (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/priority.js:72:3) at PriorityNode.remove (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/priority.js:61:15) at PriorityTree.add (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/priority.js:157:23) at Stream._initPriority (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/stream.js:101:25) at new Stream (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/stream.js:75:8) at Connection._createStream (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/connection.js:391:16) at Connection._handleHeaders (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/connection.js:438:21) at Connection._handleFrame (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/connection.js:321:10) at Parser. (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/connection.js:158:10) at emitOne (events.js:96:13) at Parser.emit (events.js:191:7) at readableAddChunk (/usr/src/app/node_modules/readable-stream/lib/_stream_readable.js:217:18) at Parser.Readable.push (/usr/src/app/node_modules/readable-stream/lib/_stream_readable.js:176:10) at Parser.Transform.push (/usr/src/app/node_modules/readable-stream/lib/_stream_transform.js:123:32) at next (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/protocol/base/parser.js:52:12) at /usr/src/app/node_modules/spdy-transport/lib/spdy-transport/protocol/http2/parser.js:71:5 name: 'AssertionError', actual: false, expected: true, operator: '==', message: 'false == true', generatedMessage: true }

Happens when I press f5 several times quickly ( I use push ).

daviddias commented 7 years ago

Seems that the later issue is also described at:

Let's follow up there.

deveshmehta7 commented 5 years ago

Just use the below package. Here we have removed the assertion error AssertionError: false == true

"spdy": "https://github.com/deveshmehta7/node-spdy#assertionError",

Kuvalda commented 5 years ago

Have same problem, server crash periodically when reload page... "spdy": "^3.4.7", "stream": "0.0.2", "tls": "0.0.1",

GET /static/css/app.a1b9783855251f1ac0b945889157e0e8.css 304 2.073 ms - - assert.js:42

throw new errors.AssertionError({ ^ AssertionError [ERR_ASSERTION]: false == true

at PriorityNode.removeChild (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/priority.js:74:3)

at PriorityNode.remove (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/priority.js:62:15)

at PriorityTree.add (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/priority.js:163:23)

at Stream._initPriority (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/stream.js:101:25)

at new Stream (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/stream.js:76:8)

at Connection._createStream (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/connection.js:388:16)

at Connection._handleHeaders (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/connection.js:436:21)

at Connection._handleFrame (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/connection.js:319:10)

at Parser.<anonymous> (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/connection.js:156:10)

at emitOne (events.js:116:13)

at Parser.emit (events.js:211:7)

at addChunk (/usr/src/app/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_readable.js:291:12)

at readableAddChunk (/usr/src/app/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_readable.js:278:11)

at Parser.Readable.push (/usr/src/app/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_readable.js:245:10)

at Parser.Transform.push (/usr/src/app/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_transform.js:148:32)

at next (/usr/src/app/node_modules/spdy-transport/lib/spdy-transport/protocol/base/parser.js:53:12)