Skip to content

New connections should fail if there's an already open connection #40

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jdmoreira
Copy link
Member

@jdmoreira jdmoreira commented Aug 6, 2025

This Pull Request changes the behaviour around Connections creation.

Before this Pull Request when a new connection was requested the previous one was closed.
Now when a new connection is requested, and there is already a connection, ConnectionError.busy is thrown.

ConnectionFullStackTests had to be changed to test for the new behaviour instead of the old one and I also took the opportunity to migrate them from the old XCTest framework to the new Swift Testing framework.

I've run the Connection tests for the three different kinds of connections and made sure they passed both on iOS and macOS. (actually sendManually() fails for iOS with NFC but that's a entitlements issue that was already failing before and I will fix in a different pull request).

@jdmoreira jdmoreira self-assigned this Aug 6, 2025
@jdmoreira jdmoreira requested a review from Copilot August 6, 2025 09:55
Copy link

@Copilot 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.

Pull Request Overview

This PR changes the connection behavior to prevent multiple simultaneous connections by throwing a ConnectionError.busy error when attempting to establish a new connection while one already exists. Previously, the system would automatically close existing connections and replace them with new ones.

  • Adds a new ConnectionError.busy case to indicate an active connection exists
  • Updates connection managers to check for existing connections and throw .busy instead of replacing them
  • Modifies the SmartCard connection cleanup to be handled asynchronously when connections close
  • Updates tests from XCTest to the Swift Testing framework with proper connection lifecycle management

Reviewed Changes

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

Show a summary per file
File Description
Connection.swift Adds new busy error case and Sendable conformance
SmartCardConnection.swift Replaces automatic connection replacement with busy error and adds async cleanup
NFCConnection.swift Changes from invalidating existing connections to throwing busy error
LightningConnection.swift Removes concurrent connection task handling in favor of busy error
ConnectionFullStackTests.swift Migrates tests to Swift Testing framework and adds proper connection lifecycle testing

public enum ConnectionError: Error {
public enum ConnectionError: Error, Sendable {
/// There is an active connection.
case busy
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm open to some other naming here!

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.

1 participant