Skip to content

Conversation

@TimLico
Copy link
Contributor

@TimLico TimLico commented Feb 28, 2025

Description

There is a 100ms/3s delay on the first connection. The change is in waitForReclaimTimeout, Possible fix is to change the early-return check from in ConnectionFactory.cs, line 158.

if (_device.LastActiveTransport == newTransport )

to

if (_device.LastActiveTransport == newTransport || _device.LastActiveTransport == Transport.None)
 {
     _device.LastActiveTransport = newTransport;
     return;
 }

Inside the if statement, _device.LastActiveTransport is updated to prevent it from remaining None indefinitely, which could lead to unexpected transport behavior.

Activity

Fixes: # <YESDK-1432>

Type of change

  • Refactor (non-breaking change which improves code quality or performance)
  • 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 not work as expected)
  • This change requires a documentation update

How has this been tested?

The test case public void SwitchingBetweenTransports_ForcesThreeSecondWait() has been updated to reflect this change. Now, the first connection no longer waits for three seconds, reducing the test duration from approximately 10s to 6s.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have run dotnet format to format my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@github-actions
Copy link

Test Results: Windows

    2 files      2 suites   5s ⏱️
3 777 tests 3 777 ✅ 0 💤 0 ❌
3 779 runs  3 779 ✅ 0 💤 0 ❌

Results for commit 5a53d2d.

@github-actions
Copy link

Test Results: Ubuntu

    2 files      2 suites   5s ⏱️
3 769 tests 3 769 ✅ 0 💤 0 ❌
3 771 runs  3 771 ✅ 0 💤 0 ❌

Results for commit 5a53d2d.

@github-actions
Copy link

Code Coverage

Package Line Rate Branch Rate Complexity Health
Yubico.Core 40% 31% 4317
Yubico.YubiKey 50% 46% 19638
Summary 48% (33141 / 69228) 44% (8226 / 18909) 23955

Minimum allowed line rate is 40%

@github-actions
Copy link

Test Results: MacOS

    2 files      2 suites   5s ⏱️
3 769 tests 3 769 ✅ 0 💤 0 ❌
3 771 runs  3 771 ✅ 0 💤 0 ❌

Results for commit 5a53d2d.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR fixes an issue where the first connection experiences an unnecessary delay by changing the early-return condition in the reclaim timeout logic.

  • Updated the condition in ConnectionFactory.cs to skip waiting when the current transport is either already active or is Transport.None.
  • Adjusted the integration test in ReclaimTimeoutTests.cs to verify that the first connection completes quickly.

Reviewed Changes

File Description
Yubico.YubiKey/src/Yubico/YubiKey/ConnectionFactory.cs Updated condition to ensure _device.LastActiveTransport is set when it was previously None, enabling immediate connection.
Yubico.YubiKey/tests/integration/Yubico/YubiKey/ReclaimTimeoutTests.cs Adjusted the test to assert that the first connection is fast (under 100ms), reflecting the intended change.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

@DennisDyallo DennisDyallo merged commit 47cfb79 into develop Mar 4, 2025
12 checks passed
@DennisDyallo DennisDyallo deleted the tim/skip-waiting-for-the-first-connection-to-the-key branch March 4, 2025 15:02
@DennisDyallo DennisDyallo changed the title Skip waiting for the first connection to the key feat: Skip waiting for the first connection to the key Mar 19, 2025
@DennisDyallo DennisDyallo added this to the April release milestone Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants