alts: add close to TsiHandshaker to avoid resource leak for some impls (#6186)

* alts: add close to TsiHandshaker to avoid resource leak for some implementations

* fix linter error
This commit is contained in:
Jihun Cho 2019-09-25 13:23:52 -07:00 committed by GitHub
parent 694de41107
commit 1ab651073d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 0 deletions

View File

@ -192,4 +192,9 @@ public final class AltsTsiHandshaker implements TsiHandshaker {
public TsiFrameProtector createFrameProtector(ByteBufAllocator alloc) {
return createFrameProtector(AltsTsiFrameProtector.getMaxAllowedFrameBytes(), alloc);
}
@Override
public void close() {
handshaker.close();
}
}

View File

@ -149,4 +149,8 @@ public final class NettyTsiHandshaker {
unwrapper = null;
return internalHandshaker.createFrameProtector(alloc);
}
void close() {
internalHandshaker.close();
}
}

View File

@ -185,4 +185,9 @@ public final class TsiHandshakeHandler extends ByteToMessageDecoder {
}
}
}
@Override
protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception {
handshaker.close();
}
}

View File

@ -106,4 +106,9 @@ public interface TsiHandshaker {
* @return a new TsiFrameProtector.
*/
TsiFrameProtector createFrameProtector(ByteBufAllocator alloc);
/**
* Closes resources.
*/
void close();
}

View File

@ -479,6 +479,11 @@ public class AltsProtocolNegotiatorTest {
protectors.add(protector);
return protector;
}
@Override
public void close() {
delegate.close();
}
}
private static class InterceptingProtector implements TsiFrameProtector {

View File

@ -226,4 +226,9 @@ public class FakeTsiHandshaker implements TsiHandshaker {
public TsiFrameProtector createFrameProtector(ByteBufAllocator alloc) {
return createFrameProtector(AltsTsiFrameProtector.getMaxAllowedFrameBytes(), alloc);
}
@Override
public void close() {
// No-op
}
}