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

allow client/server to be initialised with a connected socket #1385

Merged
merged 4 commits into from
Apr 11, 2022

Conversation

jvimal-eg
Copy link
Contributor

@jvimal-eg jvimal-eg commented Apr 3, 2022

Motivation: #1353

Modifications: As outlined by @glbrntt:

  • A new entry on ConnectionTarget - New API on the ClientConnection builder
    here (the channel pool uses ConnectionTarget directly so does not need new API)
  • Some validation that we're not trying to use this API with a
    NIOTSEventLoopGroup or NIOTSEventLoop (as far as I can tell, using a file
    descriptor directly is not possible with Network.framework)
  • Tests

Result:
This allows greater flexibility in spawning the client/server; in particular, it allows unix domain sockets for sandboxed apps on macOS.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Apr 3, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: jvimal-eg / name: Vimal (eb6f7e9)

@jvimal-eg jvimal-eg marked this pull request as draft April 3, 2022 16:17
@glbrntt
Copy link
Collaborator

glbrntt commented Apr 4, 2022

re: #1353 (comment)

I would just create a new test class, something like https://github.com/grpc/grpc-swift/blob/main/Tests/GRPCTests/GRPCKeepaliveTests.swift should be a useful starting point.

@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Apr 4, 2022
@glbrntt
Copy link
Collaborator

glbrntt commented Apr 4, 2022

@jvimal-eg you'll need to run ./scripts/format.sh to fixup the formatting.

Note that the formatter version was changed recently, so make sure you're branch is up-to-date with main as well.

@jvimal-eg
Copy link
Contributor Author

@glbrntt Sounds good. I am new to Swift / NIO, and I am stumped at how to create a NIOBSDSocket.Handle that's already "connected" to use with a client's withConnectedSocket(). Any pointers on how to do it? NIOBSDSocket.Handle on mac/Linux appears to be just a file descriptor but I am a bit hesitant to use low-level APIs just to create a UDS.

@Lukasa
Copy link
Collaborator

Lukasa commented Apr 4, 2022

It's a file descriptor on all currently supported platforms, so you can safely use the regular libc APIs to create the Unix domain socket.

@jvimal-eg jvimal-eg force-pushed the jv/uds-connected-socket branch from a479e45 to 9adc755 Compare April 4, 2022 15:54
@jvimal-eg jvimal-eg marked this pull request as ready for review April 4, 2022 15:54
@jvimal-eg
Copy link
Contributor Author

@Lukasa thanks, done!

@@ -0,0 +1,72 @@
/*
* Copyright 2020, gRPC Authors All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Copyright 2020, gRPC Authors All rights reserved.
* Copyright 2022, gRPC Authors All rights reserved.

import EchoModel
@testable import GRPC
import NIOCore
@testable import NIOPosix
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can't do this I'm afraid: @testable allows us to use the internal API for NIOPosix which we shouldn't do as it could change at any time. Instead we should create the connected socket manually.

Comment on lines 62 to 63
XCTAssertThrowsError(try get.response.wait())
XCTAssertEqual(try get.status.map { $0.code }.wait(), .unavailable)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we should check that the response is as we expect and that get.status.wait().isOk.

Comment on lines 66 to 68
class ReadDroppingHandler: ChannelDuplexHandler {
typealias InboundIn = Any
typealias OutboundIn = Any

func channelRead(context: ChannelHandlerContext, data: NIOAny) {}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need this either.

Comment on lines 49 to 54
// See above comments for why we need this.
.withCallStartBehavior(.fastFailure)
.withKeepalive(.init(interval: .seconds(1), timeout: .milliseconds(100)))
.withDebugChannelInitializer { channel in
channel.pipeline.addHandler(ReadDroppingHandler(), position: .first)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need this part (or the comment above), it's not relevant to this test. The test should just check we can do an RPC.

Suggested change
// See above comments for why we need this.
.withCallStartBehavior(.fastFailure)
.withKeepalive(.init(interval: .seconds(1), timeout: .milliseconds(100)))
.withDebugChannelInitializer { channel in
channel.pipeline.addHandler(ReadDroppingHandler(), position: .first)
}

@jvimal-eg
Copy link
Contributor Author

@glbrntt thanks for your review. Apologies -- I blindly copypasta the old test without really paying attention to what it was doing. I fixed the test now.

@glbrntt
Copy link
Collaborator

glbrntt commented Apr 6, 2022

@glbrntt thanks for your review. Apologies -- I blindly copypasta the old test without really paying attention to what it was doing. I fixed the test now.

No worries!

You need to rebase your branch on main and reformat, see: #1385 (comment)

@jvimal-eg jvimal-eg force-pushed the jv/uds-connected-socket branch from 28ade48 to df845b8 Compare April 6, 2022 20:30
@jvimal-eg
Copy link
Contributor Author

@glbrntt Thanks. Rebased, reformatted, and addressed your comments.

Copy link
Collaborator

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

Great, thank you!

@glbrntt glbrntt merged commit e1a0025 into grpc:main Apr 11, 2022
@jvimal-eg jvimal-eg deleted the jv/uds-connected-socket branch May 3, 2022 14:21
bimawa pushed a commit to StreamLayer/grpc-swift that referenced this pull request Jun 17, 2022
)

Motivation: grpc#1353

Modifications: 

- A new entry on ConnectionTarget - New API on the ClientConnection builder
- Some validation that we're not trying to use this API with a
  NIOTSEventLoopGroup or NIOTSEventLoop (as far as I can tell, using a file
  descriptor directly is not possible with Network.framework)
- Tests

Result:

This allows greater flexibility in spawning the client/server; in particular, 
it allows unix domain sockets for sandboxed apps on macOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants