Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: make writeAfterFIN() return false #27996

Closed
wants to merge 1 commit into from

Conversation

lpinca
Copy link
Member

@lpinca lpinca commented May 31, 2019

If false is not returned a readable stream piped into the socket
might continue reading indefinitely until the process goes out of
memory.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

If `false` is not returned a readable stream piped into the socket
might continue reading indefinitely until the process goes out of
memory.
@lpinca
Copy link
Member Author

lpinca commented May 31, 2019

'use strict';

const net = require('net');
const { Readable } = require('stream');

const chunk = Buffer.alloc(1024);

const readable = new Readable({
  read() {
    this.push(chunk);
  }
});

const server = net.createServer(function(socket) {
  server.close();
  socket.resume();
  setTimeout(function() {
    socket.end();
  }, 100);
});

server.listen(function() {
  const socket = net.connect(this.address().port, function() {
    socket.resume();
    socket.on('error', function() {});

    readable.pipe(socket);
  });
});

@Trott
Copy link
Member

Trott commented Jun 1, 2019

Does the documentation for socket.write() need an update to reflect this?

Returns true if the entire data was flushed successfully to the kernel
buffer. Returns false if all or part of the data was queued in user memory.
['drain'][] will be emitted when the buffer is again free.

@lpinca
Copy link
Member Author

lpinca commented Jun 2, 2019

@Trott I think it's not needed. writeAfterFIN() replaces writeAfterEnd() to give the user a better error message.

When writeAfterEnd() is used writable.write() return false. An error is emitted to signal that the write has not been successful.

@addaleax addaleax added the net Issues and PRs related to the net subsystem. label Jun 2, 2019
@Trott Trott added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jun 3, 2019
@nodejs-github-bot
Copy link
Collaborator

@danbev
Copy link
Contributor

danbev commented Jun 4, 2019

Landed in 714a32c.

@danbev danbev closed this Jun 4, 2019
danbev pushed a commit that referenced this pull request Jun 4, 2019
If `false` is not returned a readable stream piped into the socket
might continue reading indefinitely until the process goes out of
memory.

PR-URL: #27996
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@lpinca lpinca deleted the return/false branch June 8, 2019 11:46
BridgeAR pushed a commit that referenced this pull request Jun 17, 2019
If `false` is not returned a readable stream piped into the socket
might continue reading indefinitely until the process goes out of
memory.

PR-URL: #27996
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@BridgeAR BridgeAR mentioned this pull request Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. net Issues and PRs related to the net subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants