本log介绍gitlab使用过程中遇到的两个问题的解决.

其一是有人post过大的merge request以至于gitlab返回500.其二是有时候遇到中文乱码的解决.

Post内容过大的fix

某sub repo 发送 merge request 后,gitlab的沙漏滚了N圈后返回了一个500错误,检查后台的production.log(若有admin权限,可以访问访问http://your_gitlab_domain/admin/logs 查看production.log这个标签),发现错误如下:

Mysql2::Error: MySQL server has gone away: UPDATE `merge_request_diffs` SET `st_commits` = '....', `state` = 'collected', `updated_at` = '2014-11-03 12:50:16' WHERE `merge_request_diffs`.`id` = 39
Mysql2::Error: closed MySQL connection: ROLLBACK
Completed 500 Internal Server Error in 1396ms
ActiveRecord::StatementInvalid (Mysql2::Error: closed MySQL connection: ROLLBACK):
app/services/merge_requests/create_service.rb:10:in `execute'
app/controllers/projects/merge_requests_controller.rb:87:in `create'

简而言之可以看到错误应该就是在和mysql上。 按照这个思路就可以很容易在google上得到更多的issue ,找到一个简单的 solution ,修改mysql的配置环境就可以。

[mysqld]
max_allowed_packet=512M

在mysqld中添加max_allowed_packet,调整值,加大为一个合适的数字即可。

然后reload下mysql的服务即可。

字符集的fix

同样,production.log,发现错误如下:

Mysql2::Error: Incorrect string value: '\xE4\xBB\x85\xE5\xB7\xB2...' for column 'st_diffs' at row 1: UPDATE `merge_request_diffs` SET `st_commits` = '---\n- :id: 1 ........ 
Completed 500 Internal Server Error in 2210ms

这个错误是由于字符集的不兼容的原因。在create database的时候建议用utf-8,若你用latin之类往往会出如上的错。这个issue很好的解决了这个问题. 进入mysql数据库对应的db,执行命令如下:

alter table merge_request_diffs default character set = utf8 collate = utf8_unicode_ci;
alter table merge_request_diffs convert to character set utf8 collate utf8_unicode_ci;

然后应该就可以继续用了。

Categories: Code

Yu

Ideals are like the stars: we never reach them, but like the mariners of the sea, we chart our course by them.

2 Comments

vfhky · November 17, 2014 at 22:38

Google Chrome 38.0.2125.111 Google Chrome 38.0.2125.111 Windows 7 x64 Edition Windows 7 x64 Edition

gitlab可以演示?竟然还有mysql错误。

    yu · November 18, 2014 at 23:11

    Google Chrome 38.0.2125.122 Google Chrome 38.0.2125.122 Mac OS X  10.10.1 Mac OS X 10.10.1

    @vfhky gitlab就是个私有的github嘛,后端用mysql很正常的说

Leave a Reply

Your email address will not be published. Required fields are marked *