Repository: node
Issue: TCP socket emits `error` after `close`
Labels: net

* **Version**: v12.18.0
* **Platform**: Linux 4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
* **Subsystem**: net, streams

### What steps will reproduce the bug?
**This might not be a bug itself**, but just some missing details in the documentation. The documentation about TCP sockets claim 2 things:
  1) No more events are emitted after a `close` event (this is claimed in [Writable streams](https://nodejs.org/api/stream.html#stream_event_close))
  2) A `close` event is always emitted after an `error` event (this is claimed in [net.Socket](https://nodejs.org/api/net.html#net_event_error_1)

There seems to be an edge case (writing into the socket after the close event) where both claims fail. To reproduce it, you will need to:

  1) Start a listener: `node listener.js`
```
// listener.js code
const net = require('net');                                
                                    
const server = net.createServer();                                
                                                
server.on('connection', socket => {                                 
  console.info('NEW SOCKET');                                
  socket.setEncoding('utf8');                                
  socket.on('data', data => console.info('DATA: ', data));                      
  socket.on('end', () => console.info('END'));                   
  socket.on('close', () => console.log('CLOSE'));                             
  socket.on('error', err => console.log('ERROR: ', err));                       
});                                                              
                                                                                
server.listen({host: '127.0.0.1', port: 1100});
```
  2) Start a sender: `node sender.js`
```
// sender.js code
const net = require('net');                                                                                                              
                                                                                
const socket = net.createConnection({host: '127.0.0.1', port: 1100});                                                                       
                                                            
socket.on('end', () => console.info('END'));                                    
socket.on('close', () => {                                                  
  console.info('CLOSE');
  socket.write('SOCKET CLOSE');
});                                                                             
socket.on('error', err => console.log('ERROR: ', err));
```
  3) Kill (ctrl+c) the listener process.
  4) Check that the `CLOSE` trace was written before the `ERROR` trace in the sender console.

I understand that you are not supposed to write in a socket after having received the `close` event, so this behavior might not be a bug, but it might require some changes in the docs.

I came across this behavior because it happened in one of our node.js applications in production and I was assuming in my code that `error` events could never come after `close` events. Of course, the real case was not as obvious as the example provided, and it was way trickier.