Skip to content
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

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

Merged
merged 2 commits into from Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -192,4 +192,9 @@ public TsiFrameProtector createFrameProtector(int maxFrameSize, ByteBufAllocator
public TsiFrameProtector createFrameProtector(ByteBufAllocator alloc) {
return createFrameProtector(AltsTsiFrameProtector.getMaxAllowedFrameBytes(), alloc);
}

@Override
public void close() {
handshaker.close();
}
}
Expand Up @@ -149,4 +149,8 @@ TsiFrameProtector createFrameProtector(ByteBufAllocator alloc) {
unwrapper = null;
return internalHandshaker.createFrameProtector(alloc);
}

void close() {
internalHandshaker.close();
}
}
Expand Up @@ -185,4 +185,9 @@ private void sendHandshake(ChannelHandlerContext ctx) throws GeneralSecurityExce
}
}
}

@Override
protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception {
handshaker.close();
}
}
5 changes: 5 additions & 0 deletions alts/src/main/java/io/grpc/alts/internal/TsiHandshaker.java
Expand Up @@ -106,4 +106,9 @@ public interface TsiHandshaker {
* @return a new TsiFrameProtector.
*/
TsiFrameProtector createFrameProtector(ByteBufAllocator alloc);

/**
* Closes resources.
*/
void close();
}
Expand Up @@ -479,6 +479,11 @@ public TsiFrameProtector createFrameProtector(int maxFrameSize, ByteBufAllocator
protectors.add(protector);
return protector;
}

@Override
public void close() {
delegate.close();
}
}

private static class InterceptingProtector implements TsiFrameProtector {
Expand Down
Expand Up @@ -226,4 +226,9 @@ public TsiFrameProtector createFrameProtector(int maxFrameSize, ByteBufAllocator
public TsiFrameProtector createFrameProtector(ByteBufAllocator alloc) {
return createFrameProtector(AltsTsiFrameProtector.getMaxAllowedFrameBytes(), alloc);
}

@Override
public void close() {
// No-op
}
}