Caused by: java.net.SocketTimeoutException: Read timed out;
最近在做一个复杂查询,数据量比较大,需要二十多秒才能返回得结果,提交了请求之后还没等结果吐出来就报错了,发现是因为没有添加超时配置,所以在查询又或者读取的时候超时了,我这里是读取的时候超时了,既然超时了直接把超时时间延长就好了,我用的是druid(德鲁伊)socket-timeout: 300000 # Socket读取超时:5分钟。connection-timeout: 60000 # 建立连接
### Cause: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.; An I/O error occurred while sending to the backend.; nested exception is org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
Caused by: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
Caused by: java.net.SocketTimeoutException: Read timed out;

最近在做一个复杂查询,数据量比较大,需要二十多秒才能返回得结果,提交了请求之后还没等结果吐出来就报错了,发现是因为没有添加超时配置,所以在查询又或者读取的时候超时了,我这里是读取的时候超时了,既然超时了直接把超时时间延长就好了,我用的是druid(德鲁伊)
在数据库url补上两个参数 socketTimeout=300000&loginTimeout=60000
spring:
datasource:
url: jdbc:postgresql://localhost:3306/yourdb?socketTimeout=300000&loginTimeout=60000
--------------------------------
如果你的前端用nginx反向代理的话,你可能会有504的报错,因为查询和读写都花了这么长时间,nginx有概率也会超时,所以如果504的话,nginx的超时时间也要设置延长一些
# 在 在nginx的配置文件 http/server/location 中都可以设置 / 根据你架构放置
proxy_connect_timeout 60s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
send_timeout 300s;
# 若是大文件或流式响应,考虑关闭 proxy_buffering
# proxy_buffering off;
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)