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

lightway-client: Register Ctrl-C handler later #12

Merged
merged 1 commit into from
May 29, 2024

Conversation

xv-ian-c
Copy link
Contributor

@xv-ian-c xv-ian-c commented May 28, 2024

... right before the main event loop begins.

I used the wrong IP address in a test and was therefore blocking before reaching the mainloop, in io::outside::Tcp::new, I suppose TCP would eventually have timed out but in the meantime I was unable to Ctrl-C out of it since the handler had been registered but nothing was yet receiving from ctrlc_rx. By defering the registration we leave the default OS behaviour (term the process) in place until we are ready to deal with things ourselves.

It can be reproduced with the following if there is no server running:

$ sudo ip netns exec lightway-client ./target/debug/lightway-client --config-file tests/client/client_config.yaml --mode tcp --ca-cert ca.crt --server 192.168.100.1:443

I don't think there is a similar failure mode for the server side, since it
receives rather than initiates connections, but make the same change there
nonetheless, there might be other similar issues with another step of the setup
process.

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)

@xv-ian-c xv-ian-c requested a review from a team as a code owner May 28, 2024 13:45
Copy link

github-actions bot commented May 28, 2024

Code coverage summary for e0ccd5c:

Filename                                                     Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
lightway-app-utils/src/args/cipher.rs                              7                 7     0.00%           2                 2     0.00%           6                 6     0.00%           0                 0         -
lightway-app-utils/src/args/connection_type.rs                     7                 7     0.00%           2                 2     0.00%           6                 6     0.00%           0                 0         -
lightway-app-utils/src/args/duration.rs                            9                 9     0.00%           5                 5     0.00%          11                11     0.00%           0                 0         -
lightway-app-utils/src/args/logging.rs                            20                20     0.00%           4                 4     0.00%          18                18     0.00%           0                 0         -
lightway-app-utils/src/connection_ticker.rs                       35                 4    88.57%          17                 2    88.24%         182                 5    97.25%           0                 0         -
lightway-app-utils/src/dplpmtud_timer.rs                          53                 7    86.79%          22                 4    81.82%         323                11    96.59%           0                 0         -
lightway-app-utils/src/event_stream.rs                             6                 0   100.00%           3                 0   100.00%          13                 0   100.00%           0                 0         -
lightway-app-utils/src/iouring.rs                                 95                95     0.00%          20                20     0.00%         186               186     0.00%           0                 0         -
lightway-app-utils/src/tun.rs                                     89                89     0.00%          23                23     0.00%          96                96     0.00%           0                 0         -
lightway-app-utils/src/utils.rs                                    8                 8     0.00%           1                 1     0.00%           9                 9     0.00%           0                 0         -
lightway-client/src/args.rs                                       32                32     0.00%          30                30     0.00%          30                30     0.00%           0                 0         -
lightway-client/src/io/inside/tun.rs                              42                42     0.00%           7                 7     0.00%          50                50     0.00%           0                 0         -
lightway-client/src/io/outside/tcp.rs                             47                47     0.00%           9                 9     0.00%          43                43     0.00%           0                 0         -
lightway-client/src/io/outside/udp.rs                             58                58     0.00%          11                11     0.00%          58                58     0.00%           0                 0         -
lightway-client/src/io/outside/udp/sockopt.rs                     23                23     0.00%           4                 4     0.00%          66                66     0.00%           0                 0         -
lightway-client/src/keepalive.rs                                 185                35    81.08%          46                 7    84.78%         397                21    94.71%           0                 0         -
lightway-client/src/lib.rs                                       130               130     0.00%          16                16     0.00%         187               187     0.00%           0                 0         -
lightway-client/src/main.rs                                       20                20     0.00%           2                 2     0.00%         118               118     0.00%           0                 0         -
lightway-core/src/borrowed_bytesmut.rs                            87                 1    98.85%          24                 0   100.00%         196                 1    99.49%           0                 0         -
lightway-core/src/builder_predicates.rs                           20                10    50.00%           4                 2    50.00%          32                16    50.00%           0                 0         -
lightway-core/src/cipher.rs                                       10                 0   100.00%           4                 0   100.00%          14                 0   100.00%           0                 0         -
lightway-core/src/connection.rs                                  469               231    50.75%          50                19    62.00%         652               272    58.28%           0                 0         -
lightway-core/src/connection/builders.rs                          64                24    62.50%          18                 7    61.11%         219                49    77.63%           0                 0         -
lightway-core/src/connection/dplpmtud.rs                         767                90    88.27%          69                 1    98.55%         950                11    98.84%           0                 0         -
lightway-core/src/connection/fragment_map.rs                     141                13    90.78%          30                 1    96.67%         293                 8    97.27%           0                 0         -
lightway-core/src/connection/io_adapter.rs                       146                17    88.36%          42                 5    88.10%         338                23    93.20%           0                 0         -
lightway-core/src/context.rs                                      97                29    70.10%          28                 9    67.86%         201                42    79.10%           0                 0         -
lightway-core/src/context/ip_pool.rs                               7                 3    57.14%           1                 0   100.00%           6                 0   100.00%           0                 0         -
lightway-core/src/context/server_auth.rs                          14                11    21.43%           4                 3    25.00%          19                15    21.05%           0                 0         -
lightway-core/src/io.rs                                            3                 3     0.00%           3                 3     0.00%          10                10     0.00%           0                 0         -
lightway-core/src/lib.rs                                           9                 6    33.33%           4                 1    75.00%          18                 9    50.00%           0                 0         -
lightway-core/src/metrics.rs                                       7                 7     0.00%           3                 3     0.00%          10                10     0.00%           0                 0         -
lightway-core/src/packet.rs                                       29                 9    68.97%           5                 2    60.00%          31                 7    77.42%           0                 0         -
lightway-core/src/plugin.rs                                       73                11    84.93%          27                 7    74.07%         164                11    93.29%           0                 0         -
lightway-core/src/utils.rs                                       111                19    82.88%          26                 0   100.00%         184                11    94.02%           0                 0         -
lightway-core/src/version.rs                                      49                 0   100.00%          24                 0   100.00%          94                 0   100.00%           0                 0         -
lightway-core/src/wire.rs                                        152                22    85.53%          39                 1    97.44%         262                 3    98.85%           0                 0         -
lightway-core/src/wire/auth_failure.rs                             9                 1    88.89%           3                 0   100.00%          19                 0   100.00%           0                 0         -
lightway-core/src/wire/auth_request.rs                           152                12    92.11%          36                 0   100.00%         289                 0   100.00%           0                 0         -
lightway-core/src/wire/auth_success_with_config_ipv4.rs           69                 4    94.20%          13                 0   100.00%         145                 0   100.00%           0                 0         -
lightway-core/src/wire/data.rs                                    21                 1    95.24%           7                 0   100.00%          41                 0   100.00%           0                 0         -
lightway-core/src/wire/data_frag.rs                               47                 1    97.87%          19                 0   100.00%          94                 0   100.00%           0                 0         -
lightway-core/src/wire/ping.rs                                    24                 3    87.50%           8                 0   100.00%          69                 0   100.00%           0                 0         -
lightway-core/src/wire/pong.rs                                    15                 2    86.67%           5                 0   100.00%          34                 0   100.00%           0                 0         -
lightway-core/src/wire/server_config.rs                           20                 2    90.00%           5                 0   100.00%          44                 0   100.00%           0                 0         -
lightway-server/src/args.rs                                       29                29     0.00%          27                27     0.00%          27                27     0.00%           0                 0         -
lightway-server/src/connection.rs                                 48                48     0.00%          23                23     0.00%         105               105     0.00%           0                 0         -
lightway-server/src/connection_manager.rs                         99                99     0.00%          31                31     0.00%         187               187     0.00%           0                 0         -
lightway-server/src/connection_manager/connection_map.rs          92                11    88.04%          28                 3    89.29%         275                10    96.36%           0                 0         -
lightway-server/src/io/inside/tun.rs                              27                27     0.00%           7                 7     0.00%          34                34     0.00%           0                 0         -
lightway-server/src/io/outside/tcp.rs                             33                33     0.00%           6                 6     0.00%          40                40     0.00%           0                 0         -
lightway-server/src/io/outside/udp.rs                             41                41     0.00%          10                10     0.00%          59                59     0.00%           0                 0         -
lightway-server/src/ip_manager.rs                                134                24    82.09%          29                 4    86.21%         325                26    92.00%           0                 0         -
lightway-server/src/lib.rs                                        79                79     0.00%          12                12     0.00%         123               123     0.00%           0                 0         -
lightway-server/src/main.rs                                       39                39     0.00%           5                 5     0.00%         128               128     0.00%           0                 0         -
lightway-server/src/metrics.rs                                    70                68     2.86%          29                28     3.45%         113               110     2.65%           0                 0         -
lightway-server/src/statistics.rs                                 56                24    57.14%           9                 4    55.56%         104                42    59.62%           0                 0         -
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                           4225              1687    60.07%         941               373    60.36%        7747              2310    70.18%           0                 0         -

✅ Region coverage 60% passes
✅ Line coverage 70% passes

... right before the main event loop begins.

I used the wrong IP address in a test and was therefore blocking before
reaching the mainloop, in `io::outside::Tcp::new`, I suppose TCP would
eventually have timed out but in the meantime I was unable to Ctrl-C out of it
since the handler had been registered but nothing was yet receiving from
`ctrlc_rx`. By defering the registration we leave the default OS behaviour
(term the process) in place until we are ready to deal with things ourselves.

It can be reproduced with the following if there is no server running:

```console
$ sudo ip netns exec lightway-client ./target/debug/lightway-client --config-file tests/client/client_config.yaml --mode tcp --ca-cert ca.crt --server 192.168.100.1:443
```

I don't think there is a similar failure mode for the server side, since it
receives rather than initiates connections, but make the same change there
nonetheless, there might be other similar issues with another step of the setup
process.
@xv-ian-c xv-ian-c force-pushed the client-register-ctrlc-handler-later branch from 0bc4bf4 to e0ccd5c Compare May 28, 2024 14:08
@xv-ian-c xv-ian-c merged commit de6bb3b into main May 29, 2024
10 checks passed
@xv-ian-c xv-ian-c deleted the client-register-ctrlc-handler-later branch May 29, 2024 07:29
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.

3 participants