我有一个长时间运行的查询,大约48分钟后超时。
命令超时设置为2小时,连接超时设置为17分钟。
什么会导致查询引发超时? (我假设必须有其他我忽略的东西?)
Npgsql.NpgsqlException:
A timeout has occured. If you were establishing a connection, increase Timeout value in ConnectionString. If you were executing a command, increase the CommandTimeout value in ConnectionString or in your NpgsqlCommand object.
at Npgsql.NpgsqlState.ProcessBackendResponsesEnum(NpgsqlConnector context) in C:\projects\Npgsql2\src\Npgsql\NpgsqlState.cs:line 384
at Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb) in C:\projects\Npgsql2\src\Npgsql\NpgsqlCommand.cs:line 611
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior cb) in C:\projects\Npgsql2\src\Npgsql\NpgsqlCommand.cs:line 591
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in C:\projects\Npgsql2\src\Npgsql\NpgsqlCommand.cs:line 538
其他信息:
postgres日志显示以下“错误”:
cancelling statement due to user request
查询在昨晚的不同时间针对不同的日期范围运行了两次,两次失败并出现相同的错误,并且在运行相同的时间后 - “00:48:24.909” 和“00:48:24.936”
此外,之前的查询时间不超过00:47:40,因此这表明其他因素导致超时时间为48分钟。
我在postgres配置文件中看不到任何内容,是否有其他我可以查看的内容?
答案 0 :(得分:2)
这是Npgsql中的一个错误。我刚刚验证了它。它是fixed on 03/10/2013,但从那以后一直没有稳定的发布。目前看来,你必须建立现有的资源来解决这个问题。
这是由Socket.Poll()采用Int32微秒参数和Socket.Poll()本身的错误组合而引起的。
首先,2小时转换为-1,389,934,592微秒(7200秒* 1,000,000),其绝对值约为48分钟。
其次,Socket.Poll() documentation州:
如果您想无限期地等待响应,请将microSeconds参数设置为负整数。
相反,它似乎转换为绝对值,大约48分钟,所以这是你的奇怪但可预测的超时。
答案 1 :(得分:0)
我不确定为什么这是答案,也许是NpgSQL中的一个错误?我也无法解释是什么让CommandTimeOut在48分钟(这必须默认在某处,但不在我的代码中,更奇怪的是不会默认为documentation中指定的20秒。)< / p>
但要解决此问题,您需要在运行查询之前在命令对象上设置CommandTimeOut,而不是在连接对象上。