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

Fix Reference Count Leak #488

Merged
merged 1 commit into from
Apr 16, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.rsocket.fragmentation;

import static io.rsocket.framing.PayloadFrame.createPayloadFrame;
import static io.rsocket.util.DisposableUtil.disposeQuietly;
import static io.rsocket.util.DisposableUtils.disposeQuietly;
import static java.lang.Math.min;

import io.netty.buffer.ByteBuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.rsocket.fragmentation;

import static io.rsocket.util.DisposableUtil.disposeQuietly;
import static io.rsocket.util.DisposableUtils.disposeQuietly;
import static io.rsocket.util.RecyclerFactory.createRecycler;

import io.netty.buffer.ByteBuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package io.rsocket.framing;

import static io.netty.util.ReferenceCountUtil.release;
import static java.nio.charset.StandardCharsets.UTF_8;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.util.Recycler.Handle;
import io.netty.util.ReferenceCounted;
import java.util.Objects;
import reactor.util.annotation.Nullable;

Expand Down Expand Up @@ -51,7 +53,7 @@ abstract class AbstractRecyclableFrame<SELF extends AbstractRecyclableFrame<SELF
@SuppressWarnings("unchecked")
public final void dispose() {
if (byteBuf != null) {
byteBuf.release();
release(byteBuf);
}

byteBuf = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ default int getDataLength() {
* it.
*
* @return the data directly
* @see #getDataAsUtf8()
* @see #mapData(Function)
*/
ByteBuf getUnsafeData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.rsocket.framing;

import static io.netty.util.ReferenceCountUtil.release;
import static io.rsocket.framing.FrameType.ERROR;
import static io.rsocket.util.RecyclerFactory.createRecycler;

Expand Down Expand Up @@ -70,7 +71,13 @@ public static ErrorFrame createErrorFrame(ByteBuf byteBuf) {
public static ErrorFrame createErrorFrame(
ByteBufAllocator byteBufAllocator, int errorCode, @Nullable String data) {

return createErrorFrame(byteBufAllocator, errorCode, getUtf8AsByteBuf(data));
ByteBuf dataByteBuf = getUtf8AsByteBuf(data);

try {
return createErrorFrame(byteBufAllocator, errorCode, dataByteBuf);
} finally {
release(dataByteBuf);
}
}

/**
Expand Down
13 changes: 11 additions & 2 deletions rsocket-core/src/main/java/io/rsocket/framing/ExtensionFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.rsocket.framing;

import static io.netty.util.ReferenceCountUtil.release;
import static io.rsocket.framing.FrameType.EXT;
import static io.rsocket.util.RecyclerFactory.createRecycler;

Expand Down Expand Up @@ -79,8 +80,16 @@ public static ExtensionFrame createExtensionFrame(
@Nullable String metadata,
@Nullable String data) {

return createExtensionFrame(
byteBufAllocator, ignore, extendedType, getUtf8AsByteBuf(metadata), getUtf8AsByteBuf(data));
ByteBuf metadataByteBuf = getUtf8AsByteBuf(metadata);
ByteBuf dataByteBuf = getUtf8AsByteBuf(data);

try {
return createExtensionFrame(
byteBufAllocator, ignore, extendedType, metadataByteBuf, dataByteBuf);
} finally {
release(metadataByteBuf);
release(dataByteBuf);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ default Optional<Integer> getMetadataLength() {
* if you store it.
*
* @return the metadata directly, or {@code null} if the Metadata flag is not set
* @see #getMetadataAsUtf8()
* @see #mapMetadata(Function)
*/
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.rsocket.framing;

import static io.netty.util.ReferenceCountUtil.release;
import static io.rsocket.framing.FrameType.METADATA_PUSH;
import static io.rsocket.util.RecyclerFactory.createRecycler;

Expand Down Expand Up @@ -69,8 +70,13 @@ public static MetadataPushFrame createMetadataPushFrame(ByteBuf byteBuf) {
public static MetadataPushFrame createMetadataPushFrame(
ByteBufAllocator byteBufAllocator, String metadata) {

return createMetadataPushFrame(
byteBufAllocator, getUtf8AsByteBufRequired(metadata, "metadata must not be null"));
ByteBuf metadataByteBuf = getUtf8AsByteBufRequired(metadata, "metadata must not be null");

try {
return createMetadataPushFrame(byteBufAllocator, metadataByteBuf);
} finally {
release(metadataByteBuf);
}
}

/**
Expand Down
12 changes: 10 additions & 2 deletions rsocket-core/src/main/java/io/rsocket/framing/PayloadFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.rsocket.framing;

import static io.netty.util.ReferenceCountUtil.release;
import static io.rsocket.util.RecyclerFactory.createRecycler;

import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -78,8 +79,15 @@ public static PayloadFrame createPayloadFrame(
@Nullable String metadata,
@Nullable String data) {

return createPayloadFrame(
byteBufAllocator, follows, complete, getUtf8AsByteBuf(metadata), getUtf8AsByteBuf(data));
ByteBuf metadataByteBuf = getUtf8AsByteBuf(metadata);
ByteBuf dataByteBuf = getUtf8AsByteBuf(data);

try {
return createPayloadFrame(byteBufAllocator, follows, complete, metadataByteBuf, dataByteBuf);
} finally {
release(metadataByteBuf);
release(dataByteBuf);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.rsocket.framing;

import static io.netty.util.ReferenceCountUtil.release;
import static io.rsocket.util.RecyclerFactory.createRecycler;

import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -83,13 +84,16 @@ public static RequestChannelFrame createRequestChannelFrame(
@Nullable String metadata,
@Nullable String data) {

return createRequestChannelFrame(
byteBufAllocator,
follows,
complete,
initialRequestN,
getUtf8AsByteBuf(metadata),
getUtf8AsByteBuf(data));
ByteBuf metadataByteBuf = getUtf8AsByteBuf(metadata);
ByteBuf dataByteBuf = getUtf8AsByteBuf(data);

try {
return createRequestChannelFrame(
byteBufAllocator, follows, complete, initialRequestN, metadataByteBuf, dataByteBuf);
} finally {
release(metadataByteBuf);
release(dataByteBuf);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.rsocket.framing;

import static io.netty.util.ReferenceCountUtil.release;
import static io.rsocket.util.RecyclerFactory.createRecycler;

import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -74,8 +75,16 @@ public static RequestFireAndForgetFrame createRequestFireAndForgetFrame(
@Nullable String metadata,
@Nullable String data) {

return createRequestFireAndForgetFrame(
byteBufAllocator, follows, getUtf8AsByteBuf(metadata), getUtf8AsByteBuf(data));
ByteBuf metadataByteBuf = getUtf8AsByteBuf(metadata);
ByteBuf dataByteBuf = getUtf8AsByteBuf(data);

try {
return createRequestFireAndForgetFrame(
byteBufAllocator, follows, metadataByteBuf, dataByteBuf);
} finally {
release(metadataByteBuf);
release(dataByteBuf);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.rsocket.framing;

import static io.netty.util.ReferenceCountUtil.release;
import static io.rsocket.util.RecyclerFactory.createRecycler;

import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -74,8 +75,15 @@ public static RequestResponseFrame createRequestResponseFrame(
@Nullable String metadata,
@Nullable String data) {

return createRequestResponseFrame(
byteBufAllocator, follows, getUtf8AsByteBuf(metadata), getUtf8AsByteBuf(data));
ByteBuf metadataByteBuf = getUtf8AsByteBuf(metadata);
ByteBuf dataByteBuf = getUtf8AsByteBuf(data);

try {
return createRequestResponseFrame(byteBufAllocator, follows, metadataByteBuf, dataByteBuf);
} finally {
release(metadataByteBuf);
release(dataByteBuf);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.rsocket.framing;

import static io.netty.util.ReferenceCountUtil.release;
import static io.rsocket.util.RecyclerFactory.createRecycler;

import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -79,12 +80,16 @@ public static RequestStreamFrame createRequestStreamFrame(
@Nullable String metadata,
@Nullable String data) {

return createRequestStreamFrame(
byteBufAllocator,
follows,
initialRequestN,
getUtf8AsByteBuf(metadata),
getUtf8AsByteBuf(data));
ByteBuf metadataByteBuf = getUtf8AsByteBuf(metadata);
ByteBuf dataByteBuf = getUtf8AsByteBuf(data);

try {
return createRequestStreamFrame(
byteBufAllocator, follows, initialRequestN, metadataByteBuf, dataByteBuf);
} finally {
release(metadataByteBuf);
release(dataByteBuf);
}
}

/**
Expand Down
18 changes: 13 additions & 5 deletions rsocket-core/src/main/java/io/rsocket/framing/ResumeFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.rsocket.framing;

import static io.netty.util.ReferenceCountUtil.release;
import static io.rsocket.framing.FrameType.RESUME;
import static io.rsocket.framing.LengthUtils.getLengthAsUnsignedShort;
import static io.rsocket.util.NumberUtils.requireUnsignedShort;
Expand Down Expand Up @@ -70,12 +71,19 @@ public static ResumeFrame createResumeFrame(
long lastReceivedServerPosition,
long firstAvailableClientPosition) {

return createResumeFrame(
byteBufAllocator,
ByteBuf resumeIdentificationTokenByteBuf =
getUtf8AsByteBufRequired(
resumeIdentificationToken, "resumeIdentificationToken must not be null"),
lastReceivedServerPosition,
firstAvailableClientPosition);
resumeIdentificationToken, "resumeIdentificationToken must not be null");

try {
return createResumeFrame(
byteBufAllocator,
resumeIdentificationTokenByteBuf,
lastReceivedServerPosition,
firstAvailableClientPosition);
} finally {
release(resumeIdentificationToken);
}
}

/**
Expand Down
Loading