Skip to content

TypeError occur with http2ServerRequest.socket.destroy() #22855

Closed
@sogaani

Description

@sogaani

I met following error when call http2ServerRequest.socket.destroy();

internal/http2/core.js:1467
  const ret = stream[kHandle].trailers(headersList);
                              ^

TypeError: Cannot read property 'trailers' of undefined
    at Immediate.finishSendTrailers (internal/http2/core.js:1467:31)
    at runCallback (timers.js:695:11)
    at tryOnImmediate (timers.js:665:5)
    at processImmediate (timers.js:647:5)

The minimal code to reproduce.

const http2 = require('http2');
const {
    HTTP2_HEADER_PATH,
    HTTP2_HEADER_METHOD,
} = http2.constants;

const app = http2.createServer((req, res) => {
    res.end('hello');
    setImmediate( ()=>{ req.socket.destroy(); });
});

app.listen(8080, () => {
    const session = http2.connect('http://localhost:8080');
    const request = session.request({ [HTTP2_HEADER_PATH]: '/', [HTTP2_HEADER_METHOD]: 'get' });
    request.once('response', (headers, flags) => {
        let data = '';
        request.on('data', (chunk) => { data += chunk; });
        request.on('end', () => { console.log(data); });
    });
    request.end();
});

node: version

$ node -v
v10.10.0

I guess we should check if stream destroyed in finishSendTrailers, or we should not use setImmeidiate to call finishSendTrailers.
Currently we can call http2Session.destroy(); which delete some property while finishSendTrailers is listed in nodejs eventloop and it lead to an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions