[CONJ-671] MariaDb bulk threads occupy full cpu(99%) while db connections broken Created: 2019-01-07  Updated: 2019-02-08  Resolved: 2019-01-11

Status: Closed
Project: MariaDB Connector/J
Component/s: protocol
Affects Version/s: N/A
Fix Version/s: 1.8.0, 2.4.0

Type: Bug Priority: Major
Reporter: Zac Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None

Attachments: PNG File 2019-01-07_193656.png     PNG File 2019-01-07_193724.png    
Issue Links:
Problem/Incident
causes CONJ-563 Thread leak reported by Tomcat when u... Closed

 Description   

Caused by: java.sql.SQLNonTransientConnectionException: (conn:59) Could not send query: 断开的管道 (Write failed)
	at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:156)
	at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:118)
	at org.mariadb.jdbc.MariaDbStatement.executeBatchExceptionEpilogue(MariaDbStatement.java:295)
	... 9 more
Caused by: java.sql.SQLException: Could not send query: 断开的管道 (Write failed)
	at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.handleIoException(AbstractQueryProtocol.java:1488)
	at org.mariadb.jdbc.internal.protocol.AbstractMultiSend.executeBatchStandard(AbstractMultiSend.java:290)
	at org.mariadb.jdbc.internal.protocol.AbstractMultiSend.executeBatch(AbstractMultiSend.java:190)
	at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeBatch(AbstractQueryProtocol.java:371)
	at org.mariadb.jdbc.MariaDbStatement.internalBatchExecution(MariaDbStatement.java:1268)
	at org.mariadb.jdbc.MariaDbStatement.executeBatch(MariaDbStatement.java:1222)
	... 8 more
Caused by: java.net.SocketException: 断开的管道 (Write failed)
	at java.net.SocketOutputStream.socketWrite0(Native Method)
	at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
	at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
	at org.mariadb.jdbc.internal.io.output.StandardPacketOutputStream.flushBuffer(StandardPacketOutputStream.java:103)
	at org.mariadb.jdbc.internal.io.output.AbstractPacketOutputStream.flush(AbstractPacketOutputStream.java:157)
	at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol$2.sendCmd(AbstractQueryProtocol.java:383)
	at org.mariadb.jdbc.internal.protocol.AbstractMultiSend.executeBatchStandard(AbstractMultiSend.java:229)
	... 12 more

                for (; status.sendSubCmdCounter < requestNumberByBulk; ) {
                    sendCmd(writer, results, parametersList, queries, paramCount, status, prepareResult);
                    status.sendSubCmdCounter++;
                    status.sendCmdCounter++;
 
                    if (futureReadTask == null) {
                        futureReadTask = new FutureTask<AsyncMultiReadResult>(new AsyncMultiRead(comStmtPrepare, status,
                                protocol, false, this, paramCount,
                                results, parametersList, queries, prepareResult));
                        AbstractQueryProtocol.readScheduler.execute(futureReadTask);
                    }
                }
 
                status.sendEnded = true;

if the function sendCmd() throwes exception above while runing, the status.sendEnded couldn't be set to True, then the AsyncMultiRead thread will endless loop in while

        //ensure to not finished loop while all bulk has not been send
        while (!status.sendEnded || counter < status.sendSubCmdCounter) {
            //read results for each send data
            while (counter < status.sendSubCmdCounter) {
                try {
                    protocol.getResult(results);
                } catch (SQLException qex) {
                    if (asyncMultiReadResult.getException() == null) {
                        asyncMultiReadResult.setException(bulkSend.handleResultException(qex, results,
                                parametersList, queries, counter, sendCmdInitialCounter, paramCount,
                                asyncMultiReadResult.getPrepareResult()));
                    }
                }
                counter++;
 
                if (Thread.currentThread().isInterrupted()) {
                    asyncMultiReadResult.setException(new SQLException("Interrupted reading responses ", INTERRUPTED_EXCEPTION.getSqlState(), -1));
                    break;
                }
            }
        }



 Comments   
Comment by Diego Dupin [ 2019-01-07 ]

Thanks for the clear explanation of the issue. reproduced.
The error can occur when having network outage during batch (not for "normal" exception that server send)

Generated at Thu Feb 08 03:17:27 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.