Correctly reset cached local and remote address when disconnect() is called (#9545)
Motivation: We should correctly reset the cached local and remote address when a Channel.disconnect() is called and the channel has a notion of disconnect vs close (for example DatagramChannel implementations). Modifications: - Correctly reset cached kicak abd remote address - Update testcase to cover it and so ensure all transports work in a consistent way Result: Correctly handle disconnect()
This commit is contained in:
parent
2fe2a15593
commit
3ad037470e
@ -298,9 +298,14 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
|
||||
}
|
||||
assertTrue(cc.isConnected());
|
||||
|
||||
assertNotNull(cc.localAddress());
|
||||
assertNotNull(cc.remoteAddress());
|
||||
|
||||
// Test what happens when we call disconnect()
|
||||
cc.disconnect().syncUninterruptibly();
|
||||
assertFalse(cc.isConnected());
|
||||
assertNotNull(cc.localAddress());
|
||||
assertNull(cc.remoteAddress());
|
||||
|
||||
ChannelFuture future = cc.writeAndFlush(
|
||||
buf.retain().duplicate()).awaitUninterruptibly();
|
||||
|
@ -191,6 +191,11 @@ abstract class AbstractEpollChannel extends AbstractChannel implements UnixChann
|
||||
}
|
||||
}
|
||||
|
||||
void resetCachedAddresses() {
|
||||
local = socket.localAddress();
|
||||
remote = socket.remoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doDisconnect() throws Exception {
|
||||
doClose();
|
||||
|
@ -453,6 +453,7 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
|
||||
protected void doDisconnect() throws Exception {
|
||||
socket.disconnect();
|
||||
connected = active = false;
|
||||
resetCachedAddresses();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -132,6 +132,11 @@ abstract class AbstractKQueueChannel extends AbstractChannel implements UnixChan
|
||||
doClose();
|
||||
}
|
||||
|
||||
void resetCachedAddresses() {
|
||||
local = socket.localAddress();
|
||||
remote = socket.remoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCompatible(EventLoop loop) {
|
||||
return loop instanceof KQueueEventLoop;
|
||||
|
@ -386,6 +386,7 @@ public final class KQueueDatagramChannel extends AbstractKQueueChannel implement
|
||||
protected void doDisconnect() throws Exception {
|
||||
socket.disconnect();
|
||||
connected = active = false;
|
||||
resetCachedAddresses();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -578,6 +578,9 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
boolean wasActive = isActive();
|
||||
try {
|
||||
doDisconnect();
|
||||
// Reset remoteAddress and localAddress
|
||||
remoteAddress = null;
|
||||
localAddress = null;
|
||||
} catch (Throwable t) {
|
||||
safeSetFailure(promise, t);
|
||||
closeIfClosed();
|
||||
|
Loading…
Reference in New Issue
Block a user