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

withConnectedSocket(_:channelInitializer:) in ClientBootstrap is not working #2936

Open
ktiays opened this issue Oct 19, 2024 · 0 comments
Open

Comments

@ktiays
Copy link

ktiays commented Oct 19, 2024

Expected behavior

withConnectedSocket(_:channelInitializer:) should create a channel and activate its handlers.

Actual behavior

withConnectedSocket(_:channelInitializer:) does not activate handlers of the channel it created, and further operations on it don't work.

Steps to reproduce

let fd = connectToSomewhere()

Task {
    do {
        let channel = try await bootstrap.withConnectedSocket(fd) { channel in
            channel.pipeline.addHandler(EchoHandler())
                .flatMap { _ in
                    return channel.eventLoop.makeSucceededFuture(channel)
                }
        }
        try await channel.closeFuture.get()
    } catch {
        // ...
    }
}

The code above will produce an error operationUnsupported.

SwiftNIO version/commit hash

2.75.0

System & version information

This issue is irrelevant to the operating system.

Possible reason

withConnectedSocket(_:channelInitializer:) will internally invoke withConnectedSocket(eventLoop:socket:channelInitializer:postRegisterTransformation:) method and it then invokes initializeAndRegisterChannel(channel:channelInitializer:registration:postRegisterTransformation:) method. The type of registration parameter is @escaping @Sendable (Channel) -> EventLoopFuture<Void>, which will take an any Channel as a parameter. The implementation closure is at

channel.registerAlreadyConfigured0(promise: promise)

The real registerAlreadyConfigured0(promise:) implementation from SocketChannel is not called, however, the default implementation from Channel extension is called:

promise?.fail(ChannelError._operationUnsupported)

This is an known issue of Swift: swiftlang/swift#42725

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

No branches or pull requests

1 participant