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
cluster.joinSeedNodes(...) does not throw warnings when seed hostname contains underscores #25287 #27222
Conversation
… contains underscores akka#25287
* are any unusual characters in the host string. | ||
*/ | ||
@InternalApi | ||
private[akka] def hasInvalidHostCharacters: Boolean = host.exists(_.contains("_")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could expand of course but not all cases would need all char checks.
Could in future allow a user to provide a regex but also sounds over-engineery.
Best option is have a base here, and in a given module/function add the additional applicable checks.
private def checkHostCharacters(address: Address): Unit = | ||
require( | ||
!address.hasInvalidHostCharacters, | ||
s"Joining the cluster using invalid host characters '${address.host}' in the Address is not allowed.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not saying I like a function that has a Unit signature which can throw.... but here we want to fail fast vs return something to handle.
Test PASSed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some more but otherwise looking good to add
@@ -300,8 +300,10 @@ class Cluster(val system: ExtendedActorSystem) extends Extension { | |||
* The name of the [[akka.actor.ActorSystem]] must be the same for all members of a | |||
* cluster. | |||
*/ | |||
def join(address: Address): Unit = | |||
def join(address: Address): Unit = { | |||
checkHostCharacters(address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also be added to akka.cluster.typed.Join
message (constructor check)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@patriknw I wonder if this is needed (because it isn't so simple to call this new existing in the Join
constructor from where it is in Cluster
and in typed it is immediately checked in the call to untyped. If we let it get checked in untyped it is cleaner though I agree with you.
case Join(address) =>
adaptedCluster.join(address) // executes checkHostCharacters
case JoinSeedNodes(addresses) =>
adaptedCluster.joinSeedNodes(addresses) // executes checkHostCharacters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since it's a message it will not be fail fast (at the sender side)
You can move checkHostCharacters
to Address
, or some other place that is accessible from akka-cluster-typed and akka-cluster. It doesn't have to live inside the Cluster
class since it's just stateless validation logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I originally thought it belonged in Address
but didn't know if it was too leaky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, not good in Address since the error message talks about cluster joining. Put it in Cluster
companion object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the cluster part of the message and put it in Address for more reusability. If that makes sense.
@patriknw all review suggestions pushed. |
Test FAILed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -65,6 +68,19 @@ final case class Address private (protocol: String, system: String, host: Option | |||
* `system@host:port` | |||
*/ | |||
def hostPort: String = toString.substring(protocol.length + 3) | |||
|
|||
/** INTERNAL API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird formatting here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, needed to run fmt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't "format on save" in IntelliJ working for you? That must be annoying. I never run sbt scalafmt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That became too annoying while adding something new. I may try it again in future.
cd59db2
to
e8ca314
Compare
Test PASSed. |
Test PASSed. |
#25287