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

Revamp SPI / API of ClientTransport infrastructure to fix #1012 and to simplify API #1195

Merged
merged 5 commits into from
Jun 14, 2017

Conversation

jrudolph
Copy link
Member

This was inspired by part of @ktoso's fix in #1014 but goes a bit further to simplify the transport API.

A transport is now a static constant function value that gets passed
all parameters at connection time.

That fixes #1012 where client connection settings were both kept redundantly
inside the transport and inside the settings.

It's now also possible to specify the localAddress inside the settings. Methods
in the Http entrypoint that allow specifying the localAddress explicitly will
override whatever was given in the settings. In the future we'd like to
get rid of all those parameters to simplify entrypoint signatures in Http.

There is a basic disadvantage of passing ClientConnectionSettings to the connectTo method which is that whatever settings future ClientTransport come up with, they have to be put into those ClientConnectionSettings, so this might become an even bigger grab bag than it is right now.

Fixes #1012.

A transport is now a static constant function value that gets passed
all parameters at connection time.

That fixes akka#1012 where client connection settings were both kept redundantly
inside the transport and inside the settings.

It's now also possible to specify the localAddress inside the settings. Methods
in the Http entrypoint that allow specifying the localAddress explicitly will
override whatever was given in the settings. In the future we'd like to
get rid of all those parameters to simplify entrypoint signatures in Http.
@akka-ci akka-ci added validating PR that is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed validating PR that is currently being validated by Jenkins labels Jun 13, 2017
@akka-ci
Copy link

akka-ci commented Jun 13, 2017

Test PASSed.

@ktoso ktoso self-requested a review June 13, 2017 14:32
@jrudolph jrudolph force-pushed the jr/w/1012-fix-transport-idle-timeout branch from 5aa8d17 to d87e2a8 Compare June 13, 2017 15:19
@akka-ci akka-ci added validating PR that is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed tested PR that was successfully built and tested by Jenkins validating PR that is currently being validated by Jenkins labels Jun 13, 2017
@akka-ci
Copy link

akka-ci commented Jun 13, 2017

Test FAILed.

@jrudolph
Copy link
Member Author

PLS BUILD

@akka-ci akka-ci added validating PR that is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR that is currently being validated by Jenkins labels Jun 13, 2017
@akka-ci
Copy link

akka-ci commented Jun 13, 2017

Test PASSed.

@ktoso
Copy link
Member

ktoso commented Jun 13, 2017

There is a basic disadvantage of passing ClientConnectionSettings to the connectTo method which is that whatever settings future ClientTransport come up with, they have to be put into those ClientConnectionSettings, so this might become an even bigger grab bag than it is right now.

Yeah... though perhaps won't been much more of a problem than it is already in practice; For now we only have the Proxy coming up there AFAICS; Technically we could pull off some trick like transportSettings: Map[TransportSettingKey[V], V] or something if we care about avoiding more fields in there etc (would allow keeping external projects to contribute transports - though I'm not sure that will happen or should be a goal - what was your plan about that?)

Copy link
Member

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for getting back to it swiftly; Core of the issue addressed nicely as well, which I back then referred to as the "passing around settings problem" and done in pretty clean way :-)

@@ -2,3 +2,35 @@

# Added a new method to this sealed trait
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.http.javadsl.model.MediaType#WithOpenCharset.toContentTypeWithMissingCharset")

# Move settings implementations to Java superclass, ClientConnectionSettings are marked @DoNotInherit
Copy link
Member

Choose a reason for hiding this comment

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

thanks for the meaningful comments on those filters 👍

private case class TCPTransport(localAddress: Option[InetSocketAddress], settings: ClientConnectionSettings) extends ClientTransport {
def connectTo(host: String, port: Int)(implicit system: ActorSystem): Flow[ByteString, ByteString, Future[OutgoingConnection]] =
private case object TCPTransport extends ClientTransport {
def connectTo(host: String, port: Int, settings: ClientConnectionSettings)(implicit system: ActorSystem): Flow[ByteString, ByteString, Future[OutgoingConnection]] =
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this solves the problem of it being passed in "too early and only once", good.

@@ -297,7 +297,7 @@ class HttpExt(private val config: Config)(implicit val system: ActorSystem) exte
localAddress: Option[InetSocketAddress] = None,
settings: ClientConnectionSettings = ClientConnectionSettings(system),
log: LoggingAdapter = system.log): Flow[HttpRequest, HttpResponse, Future[OutgoingConnection]] =
_outgoingConnection(host, port, settings, ConnectionContext.noEncryption(), ClientTransport.TCP(localAddress, settings), log)
_outgoingConnection(host, port, settings.withLocalAddressOverride(localAddress), ConnectionContext.noEncryption(), ClientTransport.TCP, log)
Copy link
Member

Choose a reason for hiding this comment

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

good, makes sense; this is where the passing in of the settings previously did not do what was expected AFAIR

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the problem was that ConnectionPoolSettings.withConnectionSettings(...) had no effect because the settings had already been passed to the transport.

*/
def withLocalAddressOverride(overrideLocalAddressOption: Option[InetSocketAddress]): ClientConnectionSettings =
if (overrideLocalAddressOption.isDefined) withLocalAddress(overrideLocalAddressOption)
else this
}
Copy link
Member

Choose a reason for hiding this comment

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

good 👍

final override def getRequestHeaderSizeHint: Int = requestHeaderSizeHint
final override def getWebsocketRandomFactory: Supplier[Random] = new Supplier[Random] {
override def get(): Random = websocketRandomFactory()
}
Copy link
Member

Choose a reason for hiding this comment

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

moving them up one level looks good 👍

val poolSettings =
ConnectionPoolSettings(system)
.withTransport(transport)
.withConnectionSettings(ClientConnectionSettings(system).withIdleTimeout(23.hours))
Copy link
Member

Choose a reason for hiding this comment

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

extract the 23.hours as value? a bit easier to see where it's set / expected then?

transport.out.sendComplete()

response.entity.dataBytes.utf8String.awaitResult(10.seconds) should ===("Hello World!")
}
Copy link
Member

Choose a reason for hiding this comment

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

Great test setup!

@jrudolph jrudolph force-pushed the jr/w/1012-fix-transport-idle-timeout branch from d87e2a8 to 73f48bd Compare June 14, 2017 09:23
@akka-ci akka-ci added validating PR that is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins validating PR that is currently being validated by Jenkins labels Jun 14, 2017
@akka-ci
Copy link

akka-ci commented Jun 14, 2017

Test PASSed.

@jrudolph jrudolph merged commit 9e5a653 into akka:master Jun 14, 2017
@jrudolph jrudolph deleted the jr/w/1012-fix-transport-idle-timeout branch June 14, 2017 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tested PR that was successfully built and tested by Jenkins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

idle-timeout became broken between 10.0.4 and 10.0.5?
3 participants