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

IllegalReferenceCountException exception in TextRowDecoder #24

Open
unoexperto opened this issue Nov 27, 2021 · 11 comments
Open

IllegalReferenceCountException exception in TextRowDecoder #24

unoexperto opened this issue Nov 27, 2021 · 11 comments

Comments

@unoexperto
Copy link

unoexperto commented Nov 27, 2021

@rusher I'm having similar issue with version 1.1.1-rc.

I couldn't get to the bottom of this yet but I get IllegalReferenceCountException exception in TextRowDecoder.setPosition().

It happens in line

short type = this.buf.readUnsignedByte();

because reference count of RowDecoder.buf. I'm assuming you're reusing instance of ByteBuf. So far I can't find consistent pattern to reproduce it but I can say it happens when query returns a lot of rows (80K+ items).

Sadly I'm seeing that it doesn't happen when I slow down the application (using profiler for example). Race condition somewhere?

UPD: I thought maybe it's related to spring-projects/spring-framework#26060 so I upgraded to Netty 4.1.70 but it didn't help. That's too bad since it's no-go for production :( Interestingly enough inside AbstractByteBuf.ensureAccessible() call ((UnpooledSlicedByteBuf) this).buffer.refCnt() that works via ReferenceCountUpdater returns 0 but underlying volatile int refCnt field has 1. Ah... they have wacky code in counter updater. When count is one then treat it as zero https://github.com/netty/netty/blob/ea2742b4f628dfae9523c49b22472df921d1386c/common/src/main/java/io/netty/util/internal/ReferenceCountUpdater.java#L62 but why....

Originally posted by @unoexperto in #7 (comment)

@RamonVerbruggen
Copy link

RamonVerbruggen commented May 24, 2022

Since updating to Spring Boot 2.7.0, I have the same (edit: reproducible) problem when using this r2dbc migrate tool
I'm not sure why a version 1.1.1-rc is used from spring boot, and I really hope this can be fixed before an official 1.1.1 release is made.

@RamonVerbruggen
Copy link

After some experimentation I found that the exact same software works correctly with the 1.0.3 release of the r2dbc-mariadb driver.

@rusher
Copy link
Collaborator

rusher commented May 30, 2022

This is normally corrected in 1.1.2.
Could you confirm using SNAPSHOT version ?

(snapshot are available through sonatype snapshot repository)

<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>

    <dependency>
        <groupId>org.mariadb</groupId>
        <artifactId>r2dbc-mariadb</artifactId>
        <version>1.1.2-SNAPSHOT</version>
    </dependency>

@RamonVerbruggen
Copy link

Thank you for your reply.
I have tested with 1.1.2-SNAPSHOT, and I still get the IllegalReferenceCountException.
Version 1.0.3 is working as expected.

nkonev added a commit to nkonev/r2dbc-migrate that referenced this issue Jun 9, 2022
nkonev added a commit to nkonev/r2dbc-migrate that referenced this issue Jun 10, 2022
@nkonev
Copy link

nkonev commented Jun 10, 2022

Seems I found how to fix it on r2dbc-migrate side.
The issue was produced by .last() operator https://github.com/nkonev/r2dbc-migrate/blob/5fbedb960980e2c7a25f481d9943510df6e61f1f/r2dbc-migrate-core/src/main/java/name/nkonev/r2dbc/migrate/core/R2dbcMigrate.java#L312

I need time to make new release

Try r2dbc-migrate 2.7.x

@RamonVerbruggen
Copy link

r2dbc-migrate 2.7.x works for me, but not in combination with mariadb driver version 1.1.1-rc
The error message is different, but I still get errors that I do not get with mariadb driver 1.0.3

Have not tried mariadb driver 1.1.2-SNAPSHOT with r2dbc-migrate 2.7.x

@nkonev
Copy link

nkonev commented Jun 10, 2022

I got IllegalReferenceCountException exception with mariadb driver version 1.1.1-rc in tests in r2dbc-migrate.
After I moved .last() operator to the different place the error gone and I released r2dbc-migrate 2.7.x

If you will get error with mariadb driver 1.1.2-SNAPSHOT and r2dbc-migrate 2.7.x please share new reproducer.

@RamonVerbruggen
Copy link

Sorry, my bad, let me rephrase:

With r2dbc-migrate 2.7.x and driver version 1.1.1-rc, migrate now runs fine for me, although I still get problems during later tests, that I do not get with driver 1.0.3. I will post a new issue for the driver when I get the repro figured out.

As far as I can tell, r2dbc-migrate was not the source of the problem, just the place where it showed up.

@serajin00
Copy link

I got 'refCnt: 0' exception when using 'r2dbc-mariadb:1.1.2' and also same with '1.1.1-rc'.
Only '1.0.3' have no problem.

Caused by: io.netty.util.IllegalReferenceCountException: refCnt: 0
	at io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1454) ~[netty-buffer-4.1.82.Final.jar:4.1.82.Final]
	at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1440) ~[netty-buffer-4.1.82.Final.jar:4.1.82.Final]
	at io.netty.buffer.AbstractByteBuf.readByte(AbstractByteBuf.java:730) ~[netty-buffer-4.1.82.Final.jar:4.1.82.Final]
	at io.netty.buffer.AbstractByteBuf.readUnsignedByte(AbstractByteBuf.java:744) ~[netty-buffer-4.1.82.Final.jar:4.1.82.Final]
	at org.mariadb.r2dbc.codec.TextRowDecoder.setPosition(TextRowDecoder.java:82) ~[r2dbc-mariadb-1.1.2.jar:1.1.2]
	at org.mariadb.r2dbc.codec.TextRowDecoder.get(TextRowDecoder.java:23) ~[r2dbc-mariadb-1.1.2.jar:1.1.2]
	at org.mariadb.r2dbc.MariadbReadable.get(MariadbReadable.java:33) ~[r2dbc-mariadb-1.1.2.jar:1.1.2]
	at org.mariadb.r2dbc.MariadbReadable.get(MariadbReadable.java:70) ~[r2dbc-mariadb-1.1.2.jar:1.1.2]
	at io.r2dbc.spi.Readable.get(Readable.java:80) ~[r2dbc-spi-0.9.1.RELEASE.jar:na]
	at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readFrom(MappingR2dbcConverter.java:170) ~[spring-data-r2dbc-1.5.3.jar:1.5.3]
	... 54 common frames omitted

@Camsteack
Copy link

This is happening for me as well. Impossible to use the latest version of the driver, only 1.0.2 works.
Any fix on the way ?
Cheers !

@bacca87
Copy link

bacca87 commented Nov 8, 2022

I get the same issue using micronaut and r2dbc-mariadb v1.1.2
micronaut-projects/micronaut-data#1806

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants