Skip to content

Commit

Permalink
Fix another promise leak
Browse files Browse the repository at this point in the history
This was being triggered when port was not passed
part of the url e.g. wss://example.com/some/path
as opposed to wss://example.com:443/some/path

Also added couple more locations fulfilling the promise
in case of other errors.
  • Loading branch information
mtmk committed Apr 29, 2024
1 parent 604f629 commit 36bf8c2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/Nats/NatsConnection.swift
Expand Up @@ -272,10 +272,14 @@ class ConnectionHandler: ChannelInboundHandler {
do {
let (bootstrap, upgradePromise) = try self.bootstrapConnection(to: s)
guard let host = s.host, let port = s.port else {
upgradePromise.succeed() // avoid promise leaks
throw NatsConfigError("no url")
}
self.channel = try await bootstrap.connect(host: host, port: port).get()
let connect = bootstrap.connect(host: host, port: port)
connect.cascadeFailure(to: upgradePromise)
self.channel = try await connect.get()
guard let channel = self.channel else {
upgradePromise.succeed() // avoid promise leaks
throw NatsClientError("internal error: empty channel")
}

Expand Down

0 comments on commit 36bf8c2

Please sign in to comment.