-
-
Notifications
You must be signed in to change notification settings - Fork 335
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
Enable usage of experimental inet_backend option for TCP listeners #297
Enable usage of experimental inet_backend option for TCP listeners #297
Conversation
@Maria-12648430 the test you supplied fails on MacOS. It looks like the failure is due to a problem with the socket backend itself on MacOS, not with your changes to Anyway, as I see it, the purpose of this PR is to enable us and others to activate the socket backend in the first place, not that using it works. It is experimental after all, and making it work is OTPs responsibility. With that in mind, as I see it, the following approaches are possible:
@essen what do you think? My tendency is slightly in favor of the first option, no test =^^= |
Opened https://bugs.erlang.org/browse/ERL-1284 Yes we need a test and this test is fine, OTP just needs a small fix. I have one comment about the test though. |
df68672
to
eab9859
Compare
Neither do I 😜 @essen thanks for opening the ticket at bugs.erlang.org, I didn't know they would accept just the error report but require some minimal program to demonstrate. |
Oh, I just noticed something. In If you want to look into that, to prevent you from going on a wild goose chase, I'll mention that multiple listen sockets don't seem to work right now anyway, because of reasons in the socket backend that I'll look into more deeply tomorrow. |
Thanks for the heads-up :) |
eab9859
to
018b1bb
Compare
I changed the way by which the port is set for subsequent listening sockets in ranch_acceptors_sup to use lists:keystore. This solves the problem pointed out by @juhlig. Using an unconditional lists:keystore instead of lists:keyfind(port, ...) and if different from Port -> lists:keydelete(port, ...) and then prepend {port, Port} is also more simple and has the same result, only with the port tuple replaced (possibly by the same value) or appended if not present, instead of prepended. |
Nice :) |
Thanks 😁 Btw, I noticed a loophole there, unrelated to inet_backend. It is legal to give an option multiple times in the option list, gen_tcp:listen (and ssl for that matter) will not complain, but silently take the last one of them. If multiple listen sockets are used, and the port option was given multiple times with the value of last being 0, all the sockets will end up listening on different random ports. This behavior is undocumented in OTP, probably just circumstantial, and an absolutely pointless thing to do deliberately. But it is a possibility for an unintentional misconfiguration of ranch. |
About a potential issue please open a separate PR with a test case but it's not really a priority to fix. |
Maybe next week 😉 Enjoy your weekend. |
OK so we were almost ready to release 2.0 when this dropped. Due to the problem on macOS we have chosen to merge this after releasing 2.0. We want the PR to work on macOS first. I think the patch to Erlang/OTP should just add the missing case clause, based on a quick reading of the code. I am not sure why the code singles out Thanks for the PR! And sorry this won't make it into 2.0. Feel free to send a PR to OTP. I would like to eventually test Cowboy with the |
I was mistaken about the issue with multiple listen sockets and repeated port options. Sort of, anyway: While the possibility for the described scenario does exist in ranch_acceptors_sup, a list with repeated options does not get there because ranch:filter_options drops all but the last one before that. |
You're very welcome 😄
No problem at all.
I'm pretty sure that this is way out of my league 😅 Yet 😁 |
It's probably an easy one, although time consuming without direct access to a macOS environment. First produce a test case that reproduces the problem without Ranch (you can take the test you wrote and strip Ranch bit by bit). Then either report the test case to the OTP ticket or fix the OTP code. The fix is probably to update Anyway without a macOS environment I wouldn't worry too much about it. 15 minutes feedback loops are not fun. :-) |
Not exactly a huge load of it anyway 😅 But I have some free time on my hands right now, so I'll at least have a look. |
I moved most of the tests with the socket backend in an own test group and removed the obsolete single tcp_socket_echo test. Two tests are commented out (until ERL-1287 is solved). I also tried the same in the sendfile suite, but it looks like file:sendfile does not work with the socket backend yet. |
Huh, I wonder why. Do you get errors? |
Just {error, badarg}, and this then causes a badmatch in ranch_tcp:sendfile etc. |
Minimized example: 1> {ok, S}=gen_tcp:listen(8888, [{inet_backend, socket}, {packet, raw}, binary]). |
67370b8
to
85763d9
Compare
The last commit adds socket backend tests for sendfile. They are failing right now, but should starting when OTP/23.1 arrives (https://bugs.erlang.org/browse/ERL-1293) |
4d3df8c
to
7b18793
Compare
35416e6
to
666a8ec
Compare
Hm, can't imagine what could be flaky here... it happens on different lines on different runs, the one that caused the last failure was:
and
Yes, we were just trying to find out if the issue is intermittend or reliably fails. As it worked on 23.0 once (but not always), it is intermittend. As you already made ERL-938 before and probably have some more insights into this issue, could you nudge it up at bugs erlang again? ;) |
The question is whether there is a test that doesn't fail after https://builds.ninenines.eu/logs/ranch/226/win10/ because before that, they weren't really running against OTP 23.0 because it wasn't installed (even if the logs said 23.0 that wasn't the case it was running against the version in the PATH). I don't think it's intermittent. |
If it helps, look at https://buildkite.com/ninenines/ranch-prs/builds/325, there are 3 runs for Windows. The first and last one failed on both 23.0 and 23.1, but the second one passed on 23.0 and only failed on 23.1. Doesn't seem to happen very often, though, so it looks like there definitely is something wrong starting with 23.0. Actually, we may better call it "intermittend success" instead of "intermittend failure" ;) |
The run you point to fails in both 23.0 and 23.1 though? https://builds.ninenines.eu/logs/ranch-prs/325/win10/ There's 8 failures on both 23.x in all 3 runs. |
No, look at the output in the "Log" tab, not the |
Oh right it gets overwritten. I need to improve that. Fair enough then, it doesn't always happen. But very frequently. Would be great to isolate a short snippet to reproduce the issue. |
I'll try restarting the CI machines as well just in case it's just a lack of resources due to some unrelated process. But you'll have to wait a bit for that to happen. |
No sweat ;) |
Heh... so it looks like https://bugs.erlang.org/browse/ERL-960 never got really fixed, and only popped up in ranch again because the major version changed in OTP/23... |
Or rather, it seems to be related to https://bugs.erlang.org/browse/ERL-960, not the same. We couldn't reproduce it locally with your |
OK there's probably a new issue then. |
I forget, can we merge this now? |
Oh, I completely forgot this... ^^; |
1c9656d
to
fca1334
Compare
@essen so, how about merging this? :) |
test/acceptor_SUITE.erl
Outdated
tcp_getopts_capability, | ||
tcp_getstat_capability, | ||
tcp_upgrade, | ||
%% @TODO: Enable when https://bugs.erlang.org/browse/ERL-1287 is fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been fixed so I guess the tests can be enabled again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes No... If I run them on OTP 24, they fail. I think I read somewhere (can't remember where) that while it was fixed in 23.something, it re-occurred in 24. I'm investigating, I don't have the needed version of 23 in kerl right now, it's currently building.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On top of that, with 24 tcp_error_eacces
fails with an obscure error message, but this one was definitely working before. Investigating that one, too, but it looks like this will need another report and fixing in OTP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me give you a hand? =)
I ran them on 23.3 for you, and while tcp_10_acceptors_10_listen_sockets
ultimately fails, it is for another reason, starting the listener actually works there. With 24, I can confirm that it doesn't start.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right they are related to that raw issue, OK, should have checked more thoroughly... So we can leave those disabled until an OTP release fixes the issue and then enable them for 24.x+.
I think we can merge with the 2 tests + eacces disabled for now. But we should try them against current OTP master before opening any ticket there. Want to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to do that?
Can do, but not today :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, master build was faster than expected.
Ok, so on a quick glance, it all seems to work (except for what Jan pointed out, a test failing for other reasons than the socket backend) when run on current master, even the eacces test.
So... I'll need to fix that test (needs some thinking, but I'll manage. Tomorrow. For real this time 😅), and then we can enable them when 25 is out, or 24.1 if it's already fixed in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, the 3 tests are disabled with a todo note to re-enable them when fixed (probably 24.1), and the one test that wasn't working has been fixed (this post listen callback thing came at just the right time for this :)), but it is among the disabled ones.
fca1334
to
593e875
Compare
OK let's see what tests are saying and then merge if all good. Will review at the same time. |
By the way will we need to do the same for ssl? I think we can change the backend since OTP 24. |
Hm, I don't know, will have to check. Last thing I remember was Ingela saying they won't use it in |
No, doesn't work, not even on current master. And see erlang/otp#4234 |
Yes but I have seen some bug reports around that. Guess they're for clients though. |
Merged, thanks! |
In OTP/23, there is an experimental socket backend for inet/gen_tcp. It can be activated by the undocumented {inet_backend, socket} option for gen_tcp:listen.
If present, it has to be the first option in the list. As ranch_tcp:listen modifies the options list given to it, it was not possible to activate the socket backend by specifying {inet_backend, socket} in the socket_opts parameter given to ranch:start_listener. This PR aims to change this behavior, ensuring that this option remains in the first position if present.
As this feature is experimental and undocumented in OTP, I did not add it to the documentation and specs in ranch. After all, it is not meant for widespread adoption by users, but just to enable you (@essen, @juhlig, others?) to experiment with it.