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

issue with r2dbc when first column is empty string #160

Closed
ddyycao opened this issue Oct 23, 2019 · 11 comments
Closed

issue with r2dbc when first column is empty string #160

ddyycao opened this issue Oct 23, 2019 · 11 comments

Comments

@ddyycao
Copy link

ddyycao commented Oct 23, 2019

I am using the latest version of spring-boot, spring-data-r2dbc and jasync sql

@GetMapping("/teste")
    fun teste(): Flux<Map<String, Any>> {
        return db.execute("select '' as x,'1' as y ").fetch().all()
    }
2019-10-23 17:31:24.667 ERROR 5845 --- [-netty-thread-1] c.g.jasync.sql.db.mysql.MySQLConnection  : <mysql-connection-1> Transport failure 

java.lang.IndexOutOfBoundsException: readerIndex(3) + length(2) exceeds writerIndex(3): UnpooledSlicedByteBuf(ridx: 3, widx: 3, cap: 3/3, unwrapped: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeNoCleanerDirectByteBuf(ridx: 75, widx: 84, cap: 512))
	at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1495) ~[netty-buffer-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.buffer.AbstractByteBuf.readShort(AbstractByteBuf.java:764) ~[netty-buffer-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.buffer.SwappedByteBuf.readShort(SwappedByteBuf.java:546) ~[netty-buffer-4.1.42.Final.jar:4.1.42.Final]
	at com.github.jasync.sql.db.mysql.decoder.OkDecoder.decode(OkDecoder.kt:17) ~[jasync-mysql-1.0.9.jar:na]
	at com.github.jasync.sql.db.mysql.codec.MySQLFrameDecoder.doDecoding(MySQLFrameDecoder.kt:184) ~[jasync-mysql-1.0.9.jar:na]
	at com.github.jasync.sql.db.mysql.codec.MySQLFrameDecoder.handleCommonFlow(MySQLFrameDecoder.kt:169) ~[jasync-mysql-1.0.9.jar:na]
	at com.github.jasync.sql.db.mysql.codec.MySQLFrameDecoder.decode(MySQLFrameDecoder.kt:97) ~[jasync-mysql-1.0.9.jar:na]
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:505) ~[netty-codec-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:444) ~[netty-codec-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:283) ~[netty-codec-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) [netty-transport-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044) [netty-common-4.1.42.Final.jar:4.1.42.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-common-4.1.42.Final.jar:4.1.42.Final]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.2.0.RELEASE"
    id("io.spring.dependency-management") version "1.0.8.RELEASE"
    kotlin("jvm") version "1.3.50"
    kotlin("plugin.spring") version "1.3.50"
}

group = "com.cz"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

val developmentOnly by configurations.creating
configurations {
    runtimeClasspath {
        extendsFrom(developmentOnly)
    }
    compileOnly {
        extendsFrom(configurations.annotationProcessor.get())
    }
}

repositories {
    mavenCentral()
    maven { url = uri("https://repo.spring.io/milestone") }
}

dependencies {
    implementation("org.springframework.boot.experimental:spring-boot-actuator-autoconfigure-r2dbc")
    implementation("org.springframework.boot:spring-boot-starter-actuator")
    implementation("org.springframework.boot.experimental:spring-boot-starter-data-r2dbc")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("com.github.jasync-sql:jasync-r2dbc-mysql:1.0.9")
//    {
//        exclude(group="io.projectreactor.netty")
//    }
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("io.micrometer:micrometer-registry-prometheus")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
    testImplementation("org.springframework.boot.experimental:spring-boot-test-autoconfigure-r2dbc")
    testImplementation("io.projectreactor:reactor-test")
}

dependencyManagement {
    imports {
        mavenBom("org.springframework.boot.experimental:spring-boot-bom-r2dbc:0.1.0.M2")
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

@oshai
Copy link
Contributor

oshai commented Oct 25, 2019

Is the column name on the db empty? can you please provide the table schema?
In addition it will be helpful if you can add here traces for query execution as explained here: https://github.com/jasync-sql/jasync-sql/wiki/FAQ#q-how-can-i-see-the-message-begin-sent-and-received-between-the-driver-and-the-server

@ddyycao
Copy link
Author

ddyycao commented Oct 25, 2019

"select '' as x,'1' as y "
column name is not empty, got error when first column is empty string

@oshai
Copy link
Contributor

oshai commented Oct 25, 2019

oh, I get it. there is no table.

@ddyycao
Copy link
Author

ddyycao commented Oct 25, 2019

you don't need a table to reproduce this issue, a real table will trigger this issue too

@andy-yx-chen
Copy link
Contributor

This is a duplication issue with a problem found before, that was not fixed, @ddyycao , what is the mysql server version that you are using? (please include build, running os and minor versions)

@oshai
Copy link
Contributor

oshai commented Oct 26, 2019

@andy-yx-chen can you post a link to the previous issue?

@andy-yx-chen
Copy link
Contributor

@oshai sounds very similar to #121

@ddyycao
Copy link
Author

ddyycao commented Oct 28, 2019

os: centos6
mysql-server version 8.0.17 and 5.6.35 both have same issue

@oshai
Copy link
Contributor

oshai commented Oct 28, 2019

I am investigating it.

oshai added a commit that referenced this issue Oct 29, 2019
When first value of select is empty, decoder assumes it is ok packet (like eof)
for various cases
the fix is to check the state of the query, if this is the middle of query
treat it as query processing and not ok packet
@oshai
Copy link
Contributor

oshai commented Oct 29, 2019

I found the issue - during query processing packets starts with zero are treated as ok packet (which is similar to eof). I am fixing it to work as expected.

@oshai oshai closed this as completed in 3333704 Oct 29, 2019
@oshai
Copy link
Contributor

oshai commented Oct 29, 2019

Fix is released in 1.0.10

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

3 participants