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

feat(ext/net): Add Conn.setNoDelay and Conn.setKeepAlive #13103

Merged
merged 16 commits into from
Jan 31, 2022

Conversation

yos1p
Copy link
Contributor

@yos1p yos1p commented Dec 16, 2021

Implement setNoDelay function for Deno

Closes #13057
Closes #13543

@CLAassistant
Copy link

CLAassistant commented Dec 16, 2021

CLA assistant check
All committers have signed the CLA.

@yos1p
Copy link
Contributor Author

yos1p commented Dec 16, 2021

@bnoordhuis Can I ask your opinion on this implementation? Any suggestions or changes to make? Thanks!

Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Left some comments but mostly LGTM.

Disabling Nagle isn't directly observable so there isn't a good way to verify it's actually working but there should at least be a test that verifies the API method exists.

ext/net/01_net.js Outdated Show resolved Hide resolved
ext/net/lib.deno_net.d.ts Outdated Show resolved Hide resolved
AaronO
AaronO previously requested changes Dec 16, 2021
Copy link
Contributor

@AaronO AaronO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best to best opcall args directly without any wrapping when possible (both for performance and simplicity). Given op_set_nodelay takes 2 args (rid, true/false) there's no need to wrap that in a composite struct since opcalls have a user-available arity of 2.

I added suggestions of the required changes below that you can commit

ext/net/ops.rs Outdated Show resolved Hide resolved
ext/net/ops.rs Outdated Show resolved Hide resolved
ext/net/01_net.js Outdated Show resolved Hide resolved
Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! I'll dismiss Aaron's review, his feedback has been addressed.

@bnoordhuis
Copy link
Contributor

This still needs a test, by the way.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this should be a stable API from the get go?

@yos1p
Copy link
Contributor Author

yos1p commented Dec 22, 2021

Are we sure this should be a stable API from the get go?

I'm not sure what should qualify for this to be included in the stable API. It's true that currently I don't think we can write a test for this since we need to get TcpStream from the resource table.

@bartlomieju
Copy link
Member

I don't think we can write a test for this since we need to get TcpStream from the resource table.

What is the problem with getting TcpStream from the resource table?

@yos1p
Copy link
Contributor Author

yos1p commented Dec 23, 2021

What is the problem with getting TcpStream from the resource table?

The idea that I have for the unit test is to call Deno.connect, get the TcpStream, and assert that nodelay and keepalive are disabled. Then, call op_set_nodelay and op_set_keepalive function and assert that nodelay and keepalive is enabled.

But I don't know how to call that in test environment. It's a combination of calling Deno code, and get the TcpStream via Rust.

@yos1p yos1p changed the title feat(ext/net) add op_set_nodelay feat(ext/net) add op_set_nodelay and op_set_keepalive Dec 23, 2021
@yos1p
Copy link
Contributor Author

yos1p commented Dec 24, 2021

The unit test implementation for the op_set_nodelay and op_set_keepalive is a little bit much. Not sure what you guys think. Please advise if it's necessary or how to make it more simple. I'm open to suggestions.

@bnoordhuis @bartlomieju @AaronO

@bartlomieju
Copy link
Member

What is the problem with getting TcpStream from the resource table?

The idea that I have for the unit test is to call Deno.connect, get the TcpStream, and assert that nodelay and keepalive are disabled. Then, call op_set_nodelay and op_set_keepalive function and assert that nodelay and keepalive is enabled.

But I don't know how to call that in test environment. It's a combination of calling Deno code, and get the TcpStream via Rust.

Ah I see what you mean here. Indeed this is rather involved to check. Let me think about it and I'll get back to you.

assertEquals(3, buf[2]);
assert(conn.rid > 0);

assert(readResult !== null);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that:

  1. L262 already checks whether readResult equals 3
  2. readResult is a const and assigned a primitive

Do we need this assertion or is it redundant?

assertEquals(3, buf[2]);
assert(conn.rid > 0);

assert(readResult !== null);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, since readResult is a const to which a primitive gets assigned and whose value we assert upon on L298, isn't this assertion redundant?

Apologies if I'm missing anything here (this is also probably just a nitpick anyway, so I'm sorry).

bnoordhuis added a commit to denoland/deno_std that referenced this pull request Jan 19, 2022
These methods have no directly observable side effects and should
therefore be safe to turn into no-ops. Doing so unblocks a number
of third-party modules.

Can be implemented once denoland/deno#13103
lands.
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @yos1p!

@bartlomieju bartlomieju changed the title feat(ext/net) add op_set_nodelay and op_set_keepalive feat(ext/net): Add Conn.setNoDelay and Conn.setKeepAlive Jan 31, 2022
@bartlomieju bartlomieju merged commit 3e566bb into denoland:main Jan 31, 2022
@yos1p yos1p deleted the set_nodelay branch January 31, 2022 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Keep-alive for TCP TCP setNoDelay not implemented
6 participants