Closed jak-sdk closed 1 year ago
Interesting. I double checked the code (both posted here and in dev) and there is a race condition, as the tunnel interface gets created by each tunnel thread that launches (so the 1st one needs to get going before the entries exist). However, the code async launches those threads then calls the create script, so if any of the threads hasn't gotten to that point yet, the create script could get called without the device present yet.
I'm poking at this as part of a small code rework that's underway to fix this issue.
Edit: Looking more at it, allocateHandle() is called as part of the parameter build for launching the threads, so the device should be there before the create script callback. I'm trying to reproduce this on a test instance so I can poke at this more.
Hi, thanks for the response.
the create script could get called without the device present yet
I can collect diagnostics within the create script if that helps? e.g. ip a show tun
I suspect that the create script is working correctly, as I briefly see the interface as having rp_filter = 0
, it's just that after 40ms it's set to 2
, do the async threads set this on the interface after creating it? I'm wondering if the script is running before they finish, and they are setting it back to 2?
Not explicitly. The sequence goes:
So not sure yet how this is happening. I'm poking at this and doing the same sort of script you're running:
while true; do date +"%X.%N" && cat /proc/sys/net/ipv4/conf/gwi-bWMfA7Uym7G/rp_filter; done
I get:
17:10:59.588477537 cat: /proc/sys/net/ipv4/conf/gwi-bWMfA7Uym7G/rp_filter: No such file or directory
17:10:59.592640324 2
(quite a few lines)
17:10:59.747930861 2
17:10:59.750452571 0
17:10:59.752512843 0
Which is correct for what I have (the all/rp_filter is 2, and the CREATE script sets to 0).
Does this happen on every try for you, or is it occasional?
I'm using Amazon Linux 2023, wondering if Ubuntu is doing something different (maybe NetworkManager is doing something?) - any chance you can see if you can reproduce on AL2023?
Thanks, I'll try to reproduce it on AL2023 tomorrow. If I can't then I'll see if I can find out what is changing the value with eBPF.
Does this happen on every try for you, or is it occasional?
It was quite consistent, but I wasn't changing much between tests other than trimming the script down to identify the issue, and adding delay etc.
Thanks for looking into this
I also just uploaded a dev branch that has a lot of code cleanups and some other optimizations - if you can try with that and see if the issue still occurs, that would be helpful.
Hi, apologies but I haven't been able to reproduce yet on AL2023. I've had some trouble compiling the dev branch, specifically to do with the extra Boost depenedency.
Still having trouble, when running on AL2023 I get
/opt/gwlbtun: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.30' not found
I have been running the dev branch on Ubuntu though, and unfortunately I still see the same issue
Hi,
I tracked this down to an issue with Ubuntu defaults.
Here we see the race between gwlbtun and systemd-sysctl:
# using eBPF to trace what processes are modifying rp_filter
1.102612000 15855 gwlbtun-nat-set 11 0 /proc/sys/net/ipv4/conf/gwi-khyhu33zjx6/rp_filter
1.196998000 15858 systemd-sysctl 3 0 /proc/sys/net/ipv4/conf/gwo-khyhu33zjx6/rp_filter
1.200674000 15857 systemd-sysctl 3 0 /proc/sys/net/ipv4/conf/gwi-khyhu33zjx6/rp_filter
# a different run where gwlbtun ran after systemd
0.713088000 15956 systemd-sysctl 3 0 /proc/sys/net/ipv4/conf/gwi-khyhu33zjx6/rp_filter
0.684564000 15955 gwlbtun-nat-set 11 0 /proc/sys/net/ipv4/conf/gwi-khyhu33zjx6/rp_filter
0.727283000 15957 systemd-sysctl 3 0 /proc/sys/net/ipv4/conf/gwo-khyhu33zjx6/rp_filter
Which led me to look a little closer at the defaults:
root@ip-10-20-131-201:~# grep "\*.*rp_filter" /usr/lib/sysctl.d/50-default.conf
net.ipv4.conf.*.rp_filter = 2
So my apologies but this globbed declaration caught me off guard!
Removing the line and restarting systemd-sysctl and we see
0.892057000 17533 gwlbtun-nat-set 11 0 /proc/sys/net/ipv4/conf/gwi-khyhu33zjx6/rp_filter
With no interference from systemd :)
Thank you for your time spent looking at this, Regards, Jak
P.s. As a final comment, I don't quite understand the reason for the glob when I thought that is what net.ipv4.conf.default.rp_filter
exists for
Environment Details:
I am currently running
/opt/gwlbtun -c /opt/gwlbtun-nat-setup.sh
With /opt/gwlbtun-nat-setup.sh:Sourced from https://aws.amazon.com/blogs/networking-and-content-delivery/how-to-integrate-linux-instances-with-aws-gateway-load-balancer/
System details:
Issue Description
I typically see the first packet get through the new opened interface, and rp_filter is set to 0 by the script. But after ~40ms rp_filter is set to 2
Pinging every 10ms on a freshly started gwlbtun:
Here we see that the interface goes from not existing, to being created with rp_filter=0, to then set to 2:
The workaround for this issue seems to be to delay the rp_filter update, e.g.
However this causes initial latency and doesn't guarantee to fix it, because if the delayed update to
=2
took >100ms then we would be broken again (and under load this could be possible if not likely)Note also that the default
net.ipv4.conf.default.rp_filter
is set to0
and this is not respected on newgwi-<eni>
interfaces:Can someone help me understand what might be happening and how best to ensure
rp_filter
is set to 0? This feels like a bug but I'm not sure what is setting it to 2 yet.Thanks! Jak