1'use strict';
2
3const common = require('../common');
4const http = require('http');
5
6// Fix for https://github.com/nodejs/node/issues/14368
7
8const server = http.createServer(handle);
9
10function handle(req, res) {
11  res.on('error', common.mustNotCall());
12
13  res.write('hello');
14  res.end();
15
16  setImmediate(common.mustCall(() => {
17    res.write('world', common.mustCall((err) => {
18      common.expectsError({
19        code: 'ERR_STREAM_WRITE_AFTER_END',
20        name: 'Error'
21      })(err);
22      server.close();
23    }));
24  }));
25}
26
27server.listen(0, common.mustCall(() => {
28  http.get(`http://localhost:${server.address().port}`);
29}));
30