8
votes

Dear Sonarqube community,

since update to Sonarqube 6.1 we are getting an error within Sonarqube where a Packet for query is too large. What we do: Jenkins is checking out PHP source code, then SonarQube Scanner is analyzing the source code and communicates with the SonarQube server. This process is failing with the log output in Jenkins:

org.sonarqube.ws.client.HttpException: Error 500 on http://URL-TO-SONAR/sonar/api/ce/submit?projectKey=lhind.php.PRJName&projectName=PRJName : {"errors":[{"msg":"Fail to insert data of CE task AViRLtiaB_5m8twj_1J3"}]}

  • Jenkins Version: 2.19.3
  • SonarQube Version: 6.1
  • SonarQube Scanner: 2.8
  • MySQL Version: 5.6.34
  • Driver: MySQL Connector Java
  • Driver Version: mysql-connector-java-5.1.39
  • MySQL Varaible "max_allowed_packet = 16M" (increased from 4M)
  • MySQL Varaible "innodb_log_file_size = 128M" (increased from 48M)
  • Sonar JDBC connection string: "
  • sonar.jdbc.url=jdbc:mysql://DB-URL:3306/sonar?useUnicode=true&*characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&maxAllowedPacket=16777216"

We alread increased the max packet size and innodb_log_file_size. We DO NOT had this problem with the same amount of code with SonarQube 6.1.

Any ideas?

In SonarQube we got the following exception in sonar.log file:

2016.11.23 12:35:16 ERROR web[][o.s.s.w.WebServiceEngine] Fail to process request http://SONAR-URL.de:8443/sonar/api/ce/submit?projectKey=lhind.php.PRJName&projectName=PRJName java.lang.IllegalStateException: Fail to insert data of CE task AViRLtiaB_5m8twj_1J3 at org.sonar.db.ce.CeTaskInputDao.insert(CeTaskInputDao.java:56) ~[sonar-db-6.1.jar:na] (deleted because too much text ...) at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111] **Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (24313938 > 16777216). You can change this value on the server by setting the max_allowed_packet' variable.** at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3671) ~[mysql-connector-java-5.1.39.jar:5.1.39] (deleted because too much text ...) at org.sonar.db.ce.CeTaskInputDao.insert(CeTaskInputDao.java:53) ~[sonar-db-6.1.jar:na] ... 34 common frames omitted

3
Please put your code in code blocks. It is impossible to read this.Fencer04

3 Answers

15
votes

Increase the maximum allowed packet size in MySQL on both the client and server to work around this problem.

Server

See the Resolution section here for details about how to do this on the server. The recommendation there is to set this value to 256MB. In the stacktrace above, the packet size is around 24MB.

https://confluence.atlassian.com/confkb/exceeds-max-allowed-packet-for-mysql-179443425.html

I like the link above because it describes how to increase the value without stopping the database, if that's important to you.

Client

On the client, increase the value of the maxAllowedPacket parameter in the SonarQube JDBC URL.

Reference

For more details, see the following links in the MySQL documentation.

  1. http://dev.mysql.com/doc/refman/5.7/en/packet-too-large.html

Both the client and the server have their own max_allowed_packet variable, so if you want to handle big packets, you must increase this variable both in the client and in the server.

  1. https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html

maxAllowedPacket

Maximum allowed packet size to send to server. If not set, the value of system variable 'max_allowed_packet' will be used to initialize this upon connecting. This value will not take effect if set larger than the value of 'max_allowed_packet'. Also, due to an internal dependency with the property "blobSendChunkSize", this setting has a minimum value of "8203" if "useServerPrepStmts" is set to "true".

Default: -1

Since version: 5.1.8

4
votes

I had a same issue however, we had a limitation where we could not change the MySQL server configuration (max_allowed_packet)

I was able to get this working by changing the Client side jdbc URL configurations -> leaving the server config as is.

Note that we have to use 'useServerPrepStmts=true' here.

jdbc:mysql://[dbhost]:[dbport]?useUnicode=true&rewriteBatchedStatements=true&characterEncoding=utf8&useServerPrepStmts=true&maxAllowedPacket=20000000&useSSL=false

Check the mysql connector config reference here

There is one more post on SO that talks abt Client side change in detail - check here

Hope this helps!

2
votes

Here's what I did when I had the same issue and it resolved mine.

Server Error:

Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (4237058 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable.

Check this first to know the current value:

Login to your mysql though terminal and run the bellow command. You can see the current value like below.

mysql> SHOW VARIABLES LIKE 'max_allowed_packet';

+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+
1 row in set (0.00 sec)

Set the max_allowed_packet value to something like this. Purpose is to increase the value depending on your requirement.

mysql> SET GLOBAL max_allowed_packet=512000000;

Run the following command again to see the updated value. You will have to exit the mysql (either by exit; command or by clicking close button of the CLI) and log back.

mysql> SHOW VARIABLES LIKE 'max_allowed_packet';