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
Cancelation results in Resource Leak "ByteBuf.release() was not called before it's garbage-collected" #23
Comments
|
I was able to reproduce this issue consistently using Spring Boot 2.5.4 with org.mariadb:r2dbc-mariadb:jar:1.0.1 (and 1.0.2) @Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class ResourceLeakApplicationTests {
@Container
private static MariaDBContainer mariaDB = new MariaDBContainer(DockerImageName.parse("mariadb:10.5.11"));
@DynamicPropertySource
static void setTestProperties(DynamicPropertyRegistry registry) {
registry.add("spring.r2dbc.url", () -> "r2dbc" + mariaDB.getJdbcUrl().substring(4));
// registry.add("spring.r2dbc.url", () -> "r2dbc:mysql://" + mariaDB.getContainerIpAddress() + ":" + mariaDB.getMappedPort(3306) + "/test");
registry.add("spring.r2dbc.username", () -> "test");
registry.add("spring.r2dbc.password", () -> "test");
}
@Autowired
private FooRepository repository;
@Test
void provokeLeak() throws InterruptedException {
Disposable subscribe = repository.findAll()
.doOnSubscribe(subscription -> System.out.println("Subscribe"))
.doOnCancel(() -> System.out.println("Cancel"))
.subscribe(System.out::println);
Thread.sleep(100);
subscribe.dispose();
System.gc();
Thread.sleep(100);
}
}Running this with Foo: import lombok.Value;
import org.springframework.data.annotation.Id;
@Value
public class Foo {
@Id
Long id;
String value;
}FooRepository: import org.springframework.data.repository.reactive.ReactiveCrudRepository;
public interface FooRepository extends ReactiveCrudRepository<Foo, Long> {
}Running the same code with dev.miku:r2dbc-mysql:0.8.2.RELEASE there are no leaks detected. |
|
Thanks for reporting that in detail. I'm currently testing that issue.
|
|
FWIW, in other drivers we have a discard-on-cancel operator to release items that are emitted but not consumed due to a cancel signal. In the sample above, Spring Data runs a If that applies, you could guard your queries with the discard on cancel operator. |
|
allright, buffer are now ensured to be released to pool. |
|
Thank you for the quick update. |
Using org.mariadb:r2dbc-mariadb:jar:1.0.1 in a Spring Boot 2.5.2 app (setting spring.netty.leak-detection to advanced or paranoid) I'm getting errors like this one:
I'm not sure if this is caused by the mariadb r2dbc driver or somewhere else in the stack, but the messages point to
org.mariadb.r2dbc.client.MariadbPacketDecoder.decode. Please have a look at this.The text was updated successfully, but these errors were encountered: