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

Update NWWebSocket.swift #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update NWWebSocket.swift #43

wants to merge 1 commit into from

Conversation

ajinumoto
Copy link

Fix multiple NWConnection during migrateConnection

Fix multiple NWConnection during migrateConnection
@ajinumoto
Copy link
Author

Problem:
Every time migrateConnection() is called, new NWConnection will be created. The problem appear if migrateConnection() is called multiple time, the previous NWConnection from migratedConnection variable is never closed and multiple NWConnection will be alive.

Solution
change migratedConnection to global variable and make sure its cancel() and nil first before creating new one.

@@ -244,14 +245,17 @@ open class NWWebSocket: WebSocketConnection {
/// or a `NWError` if the migration failed for some reason.
private func migrateConnection(completionHandler: @escaping (Result<WebSocketConnection, NWError>) -> Void) {

let migratedConnection = NWConnection(to: endpoint, using: parameters)
migratedConnection?.cancel()

Choose a reason for hiding this comment

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

if migrateConnection was already called and successfully ended, in the next call when you cancelling migratedConnection you cancelling current 'connection'

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.

2 participants