Skip to content

end after write stops http2 stream with trailers ending #41898

@davedoesdev

Description

@davedoesdev

Version

v16.13.1

Platform

Linux david-Latitude-E6440 5.13.0-22-generic #22-Ubuntu SMP Fri Nov 5 13:21:36 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

http2

What steps will reproduce the bug?

Run this program:

const { createServer, connect } = require('http2');
const assert = require('assert');

createServer().on('stream', function (stream) {
    stream.respond({
        ':status': 200,
        'Content-Type': 'application/octet-stream'
    });
    stream.on('end', () => {
        stream.end();
        stream.session.close();
        this.close();
    });
    stream.resume();
}).listen(7000, () => {
    connect('http://localhost:7000', function () {
        this.request({
            ':method': 'POST'
        }, {
            waitForTrailers: true
        }).on('response', function () {
            this.end('12345');
            this.on('error', err => assert.equal(err.message, 'write after end'));
            this.write('6');
        }).on('wantTrailers', function () {
            this.sendTrailers({});
        });
    });
});

How often does it reproduce? Is there a required condition?

Every time

What is the expected behavior?

Program should exit

What do you see instead?

Program doesn't exit because server stream doesn't get end event.

Additional information

If you remove the write after end (this.write('6')) then the program exits.
Something is stopping the wantTrailers event being emitted and so the client stream never ends.

Note, changing to waitForTrailers: false also makes it exit (server gets end event).

Metadata

Metadata

Assignees

No one assigned

    Labels

    http2Issues or PRs related to the http2 subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions