Skip to content

Conversation

@kp-mariappan-ramasamy
Copy link
Contributor

@kp-mariappan-ramasamy kp-mariappan-ramasamy commented Nov 28, 2025

Description

Refactor keepalive to be consistent/clear and fix tracer implementation for linux client
There are multiple commits, each solving a specific usecase/problem. It is explained in the commit messages.

Motivation and Context

Tracer implementation was not working with Linux clients.

How Has This Been Tested?

Verified connection drops out, when it detects there is a network error and not able to receive packets

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • The correct base branch is being used, if not main

@github-actions
Copy link

github-actions bot commented Nov 30, 2025

Code coverage summary for 705bfa1:

Filename                                                     Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
lightway-app-utils/src/args/cipher.rs                              5                 5     0.00%           1                 1     0.00%           5                 5     0.00%           0                 0         -
lightway-app-utils/src/args/connection_type.rs                     5                 5     0.00%           1                 1     0.00%           5                 5     0.00%           0                 0         -
lightway-app-utils/src/args/duration.rs                           22                18    18.18%           5                 4    20.00%          15                12    20.00%           0                 0         -
lightway-app-utils/src/args/ip_map.rs                             19                19     0.00%           3                 3     0.00%          13                13     0.00%           0                 0         -
lightway-app-utils/src/args/logging.rs                            37                37     0.00%           3                 3     0.00%          31                31     0.00%           0                 0         -
lightway-app-utils/src/args/nonzero_duration.rs                   24                16    33.33%           4                 3    25.00%          16                10    37.50%           0                 0         -
lightway-app-utils/src/connection_ticker.rs                      236                24    89.83%          28                 4    85.71%         126                15    88.10%           0                 0         -
lightway-app-utils/src/dplpmtud_timer.rs                         212                16    92.45%          22                 4    81.82%         117                11    90.60%           0                 0         -
lightway-app-utils/src/event_stream.rs                            19                 0   100.00%           3                 0   100.00%          11                 0   100.00%           0                 0         -
lightway-app-utils/src/sockopt/ip_mtu_discover.rs                 78                78     0.00%           6                 6     0.00%          68                68     0.00%           0                 0         -
lightway-app-utils/src/sockopt/ip_pktinfo.rs                      14                14     0.00%           1                 1     0.00%          16                16     0.00%           0                 0         -
lightway-app-utils/src/tun.rs                                    281               281     0.00%          31                31     0.00%         175               175     0.00%           0                 0         -
lightway-app-utils/src/utils.rs                                   21                21     0.00%           1                 1     0.00%          11                11     0.00%           0                 0         -
lightway-client/src/args.rs                                       35                14    60.00%           2                 1    50.00%          17                 8    52.94%           0                 0         -
lightway-client/src/dns_manager.rs                                16                16     0.00%           3                 3     0.00%          11                11     0.00%           0                 0         -
lightway-client/src/io/inside/tun.rs                              78                78     0.00%          11                11     0.00%          57                57     0.00%           0                 0         -
lightway-client/src/io/outside/tcp.rs                             80                80     0.00%          11                11     0.00%          48                48     0.00%           0                 0         -
lightway-client/src/io/outside/udp.rs                            123               123     0.00%          13                13     0.00%          74                74     0.00%           0                 0         -
lightway-client/src/keepalive.rs                                 624                53    91.51%          55                 6    89.09%         330                25    92.42%           0                 0         -
lightway-client/src/lib.rs                                       786               650    17.30%          58                47    18.97%         545               455    16.51%           0                 0         -
lightway-client/src/main.rs                                      189               189     0.00%          12                12     0.00%         147               147     0.00%           0                 0         -
lightway-client/src/platform/linux/dns_manager.rs                144                64    55.56%          16                 6    62.50%          94                40    57.45%           0                 0         -
lightway-client/src/route_manager.rs                            1008               213    78.87%          63                 7    88.89%         550               115    79.09%           0                 0         -
lightway-core/src/borrowed_bytesmut.rs                           378                 1    99.74%          24                 0   100.00%         189                 1    99.47%           0                 0         -
lightway-core/src/builder_predicates.rs                           24                12    50.00%           4                 2    50.00%          24                12    50.00%           0                 0         -
lightway-core/src/cipher.rs                                       13                 0   100.00%           2                 0   100.00%          10                 0   100.00%           0                 0         -
lightway-core/src/connection.rs                                 1487               827    44.38%          66                28    57.58%        1042               552    47.02%           0                 0         -
lightway-core/src/connection/builders.rs                         236                47    80.08%          21                 8    61.90%         245                53    78.37%           0                 0         -
lightway-core/src/connection/dplpmtud.rs                        1738                95    94.53%          63                 0   100.00%         811                 9    98.89%           0                 0         -
lightway-core/src/connection/fragment_map.rs                     380                15    96.05%          25                 0   100.00%         258                 7    97.29%           0                 0         -
lightway-core/src/connection/io_adapter.rs                       529                26    95.09%          34                 5    85.29%         276                21    92.39%           0                 0         -
lightway-core/src/connection/key_update.rs                        34                13    61.76%           5                 0   100.00%          38                19    50.00%           0                 0         -
lightway-core/src/context.rs                                     202                51    74.75%          26                11    57.69%         213                64    69.95%           0                 0         -
lightway-core/src/context/ip_pool.rs                               8                 3    62.50%           1                 0   100.00%           5                 0   100.00%           0                 0         -
lightway-core/src/context/server_auth.rs                          35                27    22.86%           4                 3    25.00%          24                20    16.67%           0                 0         -
lightway-core/src/encoding_request_states.rs                       3                 0   100.00%           1                 0   100.00%           3                 0   100.00%           0                 0         -
lightway-core/src/io.rs                                           10                10     0.00%           3                 3     0.00%           9                 9     0.00%           0                 0         -
lightway-core/src/lib.rs                                           9                 0   100.00%           3                 0   100.00%           9                 0   100.00%           0                 0         -
lightway-core/src/metrics.rs                                      55                45    18.18%          21                17    19.05%          48                38    20.83%           0                 0         -
lightway-core/src/packet.rs                                       38                10    73.68%           4                 1    75.00%          30                 6    80.00%           0                 0         -
lightway-core/src/plugin.rs                                      304                13    95.72%          21                 3    85.71%         145                 7    95.17%           0                 0         -
lightway-core/src/utils.rs                                       339                31    90.86%          22                 2    90.91%         165                17    89.70%           0                 0         -
lightway-core/src/version.rs                                      94                 0   100.00%          17                 0   100.00%          82                 0   100.00%           0                 0         -
lightway-core/src/wire.rs                                        441                44    90.02%          28                 0   100.00%         233                10    95.71%           0                 0         -
lightway-core/src/wire/auth_failure.rs                            27                 1    96.30%           3                 0   100.00%          17                 0   100.00%           0                 0         -
lightway-core/src/wire/auth_request.rs                           472                12    97.46%          26                 0   100.00%         241                 0   100.00%           0                 0         -
lightway-core/src/wire/auth_success_with_config_ipv4.rs          223                 4    98.21%          11                 0   100.00%         124                 0   100.00%           0                 0         -
lightway-core/src/wire/data.rs                                    52                 1    98.08%           5                 0   100.00%          34                 0   100.00%           0                 0         -
lightway-core/src/wire/data_frag.rs                              131                 1    99.24%          14                 0   100.00%          82                 0   100.00%           0                 0         -
lightway-core/src/wire/encoding_request.rs                        82                 2    97.56%           6                 0   100.00%          42                 1    97.62%           0                 0         -
lightway-core/src/wire/encoding_response.rs                       82                 2    97.56%           6                 0   100.00%          42                 1    97.62%           0                 0         -
lightway-core/src/wire/expresslane_config.rs                     167                 2    98.80%           8                 0   100.00%          92                 0   100.00%           0                 0         -
lightway-core/src/wire/expresslane_data.rs                       921                65    92.94%          34                 5    85.29%         450                32    92.89%           0                 0         -
lightway-core/src/wire/ping.rs                                    96                 3    96.88%           7                 0   100.00%          59                 0   100.00%           0                 0         -
lightway-core/src/wire/pong.rs                                    58                 2    96.55%           5                 0   100.00%          31                 0   100.00%           0                 0         -
lightway-core/src/wire/server_config.rs                           69                 2    97.10%           4                 0   100.00%          37                 0   100.00%           0                 0         -
lightway-server/src/auth.rs                                      282                55    80.50%          22                 6    72.73%         171                28    83.63%           0                 0         -
lightway-server/src/connection.rs                                141               141     0.00%          11                11     0.00%         110               110     0.00%           0                 0         -
lightway-server/src/connection_manager.rs                        348               348     0.00%          41                41     0.00%         281               281     0.00%           0                 0         -
lightway-server/src/connection_manager/connection_map.rs         409                18    95.60%          21                 1    95.24%         228                 7    96.93%           0                 0         -
lightway-server/src/io/inside/tun.rs                              44                44     0.00%           9                 9     0.00%          30                30     0.00%           0                 0         -
lightway-server/src/io/outside/tcp.rs                             90                90     0.00%           9                 9     0.00%          65                65     0.00%           0                 0         -
lightway-server/src/io/outside/udp.rs                            320               320     0.00%          16                16     0.00%         205               205     0.00%           0                 0         -
lightway-server/src/io/outside/udp/cmsg.rs                       197                53    73.10%          14                 5    64.29%         158                43    72.78%           0                 0         -
lightway-server/src/ip_manager.rs                                550                58    89.45%          22                 4    81.82%         247                28    88.66%           0                 0         -
lightway-server/src/ip_manager/ip_pool.rs                        542                 1    99.82%          27                 0   100.00%         252                 0   100.00%           0                 0         -
lightway-server/src/lib.rs                                       260               260     0.00%          14                14     0.00%         169               169     0.00%           0                 0         -
lightway-server/src/main.rs                                      233               233     0.00%          11                11     0.00%         123               123     0.00%           0                 0         -
lightway-server/src/metrics.rs                                   257               253     1.56%          85                83     2.35%         215               211     1.86%           0                 0         -
lightway-server/src/statistics.rs                                138                62    55.07%           8                 4    50.00%          89                37    58.43%           0                 0         -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                          16604              5317    67.98%        1187               481    59.48%        9935              3568    64.09%           0                 0         -

✅ Region coverage 67% passes
✅ Line coverage 64% passes

@kp-mariappan-ramasamy kp-mariappan-ramasamy marked this pull request as ready for review December 2, 2025 03:59
@kp-mariappan-ramasamy kp-mariappan-ramasamy requested a review from a team as a code owner December 2, 2025 03:59
@kp-mariappan-ramasamy kp-mariappan-ramasamy marked this pull request as draft December 3, 2025 04:32
and use for server's key_update_interval and client's tracer timeout
and add continuous_keepalive as config parameter.

Before the commit 3997775, we
implicitly use keepalive_interval to enable/disable keepalive.
If keepalive_interval is 0s, we do not start the keepalive task.

But in 3997775, we have enhanced
keepalive module to support continuous and
non-continuous keepalive mechanism. Non continuous keepalive was needed
when we want to check connection liveliness during network transition.

There were two problems in this commit:
- noncontinuous keepalive used the interval and timeout value
 of normal keepalive. So if the interval is 0, non-continuous keepalive
 does not work since there is no task.
- Hardcode continuous_keepalive as true in binary.
- In non-continuous mode, if there is a network change, it moved the
 state to Waiting. Hence keepalive will be sent only after the interval
 period instead of sending immediately.

This commit fixes the first two issues, by using nonzero duration
for keepalive_interval and keepalive_timeout and also adding a new
variable for continuous_keepalive.

The third problem was fixed in e129a70
When try to send Keepalive immediately in Needed state,
commit e129a70 introduces a crictial
bug where the timeout is reset after sending the Keepalive.
This is serious because the timeout value will never be triggered
if it is reset continuously. This makes keepalive timeout mechanism
fail to work during Tracer timeout or NetworkChange.

Commit 44efa8a tried to fix the bug, but
instead of fixing the timeout, it introduced another method using
failed_attempts counter to fix it. This is redundant since the existing
timeout mechanism is supposed to do this precisely.
Also it increases the timeout value to timeout * 3(MAX_FAILED_ATTEMPTS).

This commit does the following:
 - reverts the changes related to failed keepalive counter changes
 - Fixes resetting the timer using FusedFuture implementation
   FusedFuture enables the use of is_terminated() method on OptionFuture
The tx field in Keepalive struct was always Some and never set to None.
Removed the Option wrapper to simplify the code and eliminate unnecessary
checks in all methods.
Consider the following case:
- Client send keepalive request to server and the reply is lost.
  Timeout would have been started when client send request.
- Now client/server starts exchanging packets continuously triggering
  OutsideActivity message
- While handling OutsideActivity message, we reset the interval and let
  timeout run.
  So when there is continuous data exchange, we will not send any keepalive
  request, but we will wait for Reply which is sent at step 1.
  After the timeout expires, it will break the connection since it has not
  received reply.


This commit resets the timeout, which does not have this faulty behavior.
This commit does two changes:
- Remove the suspended check before setting the status to suspended
- In the block where state could be waiting or pending, we move the
  state to pending if it is Waiting. We could effectively move the
  state change outside of the if loop. Also, Instead of checking for
  Waiting state, which implicitly mean no timeout, check the timeout
  status before setting the timeout.
When there is a network interruption, (mobile) clients will
send suspend message to prevent keepalive from disconnecting lightway
session.
When the network comes back up, it send NetworkChange message to
trigger the UDP floating connection.

So we need to reset the timeout to start fresh
jsonwebtoken has a breaking change:
https://github.com/Keats/jsonwebtoken/blob/master/CHANGELOG.md#1000-2025-09-29

User has to choose now between aws_lc_rs/rust_crypto instead of default ring.
`aws_lc_rs` pulls in OpenSsl license which seems to not compatible with
AGPL3.

So went with rust_crypto.
@kp-mariappan-ramasamy kp-mariappan-ramasamy merged commit 18788f6 into main Dec 12, 2025
21 checks passed
@kp-mariappan-ramasamy kp-mariappan-ramasamy deleted the keepalive-fixes branch December 12, 2025 02:53
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.

4 participants