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
fafde4aeec
commit
1b06de76c9
@ -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();
|
||||
|
@ -200,6 +200,11 @@ abstract class AbstractEpollChannel extends AbstractChannel implements UnixChann
|
||||
}
|
||||
}
|
||||
|
||||
void resetCachedAddresses() {
|
||||
local = socket.localAddress();
|
||||
remote = socket.remoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doDisconnect() throws Exception {
|
||||
doClose();
|
||||
|
@ -439,6 +439,7 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
|
||||
protected void doDisconnect() throws Exception {
|
||||
socket.disconnect();
|
||||
connected = active = false;
|
||||
resetCachedAddresses();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -138,6 +138,11 @@ abstract class AbstractKQueueChannel extends AbstractChannel implements UnixChan
|
||||
doClose();
|
||||
}
|
||||
|
||||
void resetCachedAddresses() {
|
||||
local = socket.localAddress();
|
||||
remote = socket.remoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return socket.isOpen();
|
||||
|
@ -371,6 +371,7 @@ public final class KQueueDatagramChannel extends AbstractKQueueChannel implement
|
||||
protected void doDisconnect() throws Exception {
|
||||
socket.disconnect();
|
||||
connected = active = false;
|
||||
resetCachedAddresses();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -566,6 +566,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…
x
Reference in New Issue
Block a user