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

Implement read_ahead option (OTP-19199) #8785

Conversation

RaimoNiskanen
Copy link
Contributor

Continuation of PR #8690 that implements the read_ahead option in inet:setopts/2, that is; also for inet_backend=socket (gen_tcp_socket), with documentation, and test cases.

I saw a strange behaviour of the MGS_PEEK flag on Linux (Ubuntu 22.04 LTS).

When using MSG_PEEK through `socket` to try to avoid concatenating the header
and body binaries, instead peek the header then receive the whole packet,
this happened (header 2, incoming <<0,1,65>>, but one character at the time,
through `gen_tcp_echo_SUITE`'s slow echo server:

* recv 0 -> select ...
* recv 0 -> <<0>>
We are missing one byte for the header and try to peek it
* recv 1 peek -> timeout
* recv 1 -> select ...
New attempt to peek the header
* recv 1 peek -> <<1>>   We conclude the length field is 1 and we are missing 2 bytes
* recv 2 -> select ...
Here we don't save the state that we want 2 bytes so we start over
with the <<0>> we have and, again, peek for the rest of the header.
* recv 1 peek -> <<1,0>> ??? we asked for 1 byte, what is the <<0>>?
Here the packet decode succeeds surprisingly since we were supposed to only
have the header, so we fall back to the generic path which receives
one byte at the time.
* recv 1 -> <<65>>       ??? where did the <<1>> go?
* recv 65 -> select ... We are lost and think the length field is 65=

recv N peek means `socket:recv(_, N, [peek], 0)` (timeout 0).
We didn't store data from a peek, just use it to figure out
the packet length for a recv without peek.
@RaimoNiskanen RaimoNiskanen added this to the OTP-27.1 milestone Sep 5, 2024
@RaimoNiskanen RaimoNiskanen self-assigned this Sep 5, 2024
Copy link
Contributor

github-actions bot commented Sep 5, 2024

CT Test Results

    2 files     70 suites   1h 6m 49s ⏱️
1 545 tests 1 302 ✅ 241 💤 2 ❌
1 761 runs  1 486 ✅ 273 💤 2 ❌

For more details on these failures, see this check.

Results for commit 0e943f4.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@RaimoNiskanen RaimoNiskanen merged commit db7fe0c into erlang:maint Sep 6, 2024
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant