Github user jasobrown commented on a diff in the pull request:
https://github.com/apache/cassandra/pull/184#discussion_r161921935
--- Diff: src/java/org/apache/cassandra/streaming/StreamResultFuture.java
---
@@ -135,11 +136,13 @@ public StreamCoordinator getCoordinator()
return coordinator;
}
- private void attachConnection(InetAddress from, int sessionIndex,
Channel channel)
+ private void attachConnection(InetAddressAndPort from, int
sessionIndex, Channel channel)
{
SocketAddress addr = channel.remoteAddress();
- InetAddress connecting = (addr instanceof InetSocketAddress ?
((InetSocketAddress) addr).getAddress() : from);
- StreamSession session = coordinator.getOrCreateSessionById(from,
sessionIndex, connecting);
+ InetAddress connecting = (addr instanceof InetSocketAddress ?
((InetSocketAddress) addr).getAddress() : from.address);
+ //Need to turn connecting into a InetAddressAndPort with the
correct port. I think getting the port from "from"
+ //Will work since we don't actually have ports diverge across
network interfaces
+ StreamSession session = coordinator.getOrCreateSessionById(from,
sessionIndex, InetAddressAndPort.getByAddressOverrideDefaults(connecting,
from.port));
--- End diff --
well, because I didn't document this (at all), it's hard to know why the
hell I have to check the `addr` coming from the `channel`. Shame on me.
In the case of unit tests, if you use the `EmbeddedChannel`,
`channel.remoteAddress()` does not return an `InetSocketAddress`, but an
`EmbeddedSocketAddress`. I think the best thing to do here is:
```java
private void attachConnection(InetAddressAndPort from, int sessionIndex,
Channel channel)
{
SocketAddress addr = channel.remoteAddress();
final InetAddressAndPort connecting;
if (addr instanceof InetSocketAddress)
{
InetSocketAddress address = (InetSocketAddress)addr;
connecting =
InetAddressAndPort.getByAddressOverrideDefaults(address.getAddress(),
address.getPort());
}
else
{
// assumably the addr is an EmbeddedSocketAddress, and we only get that
when running unit tests where channel is an instance of EmbeddedChannel. In
that case, it's safe to simply use the "from" parameter.
connecting = from;
}
StreamSession session = coordinator.getOrCreateSessionById(from,
sessionIndex, connecting);
}
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]