最近基于 WebMagic 在做一个爬虫项目。在一个接口中开启爬虫爬一个网站,用的阻塞模式。
之前都没有任何问题,但是最近新的一个网站,因为爬取的时间在 30 分钟左右,等爬完了,做数据持久化操作的时候,就抛出了连接超时被关闭的异常。
希望有遇到过这种情况的大神朋友能给点解决思路。
异常如下: c.z.hikari.pool.ProxyConnection - [153] - DatebookHikariCP - Connection com.mysql.cj.jdbc.ConnectionImpl@215164ec marked as broken because of SQLSTATE(08S01), ErrorCode(0) com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 1,946,875 milliseconds ago. The last packet sent successfully to the server was 1,946,924 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoRecOnnect=true' to avoid this problem.
在数据库 url 中添加‘autoRecOnnect=true’参数,以及配置 hikari 的心跳检测都依然抛出这个错误。感觉很不合理,因为 mysql 数据库默认的超时时间是 8 小时。
下面是我 hikari 的配置 hikari: auto-commit: true connection-test-query: SELECT 1 connection-timeout: 30000 idle-timeout: 30000 max-lifetime: 1800000 maximum-pool-size: 15 minimum-idle: 5
