Why does a query time-out when it is within it's timeout limit?

*爱你&永不变心* 提交于 2019-12-01 13:19:12

It's a bug in Npgsql. I just verified it. It was fixed on 03/10/2013, but there hasn't been a stable release since then. As it currently stands you'll have to build from current sources to get around this.

It is caused by a combination of the fact that Socket.Poll() takes an Int32 microseconds argument, and by what appears to be a bug in Socket.Poll() itself.

First, 2 hours converts to -1,389,934,592 microseconds (7200 seconds * 1,000,000), the absolute value of which is about 48 minutes.

Second, the Socket.Poll() documentation states:

set the microSeconds parameter to a negative integer if you would like to wait indefinitely for a response.

Instead, it appears to convert to the absolute value, about 48 minutes, so there's your odd but predictable timeout.

I'm unsure why this is the answer, perhaps a bug in NpgSQL? I also can't explain what makes the CommandTimeOut at 48 minutes (this must be defaulted somewhere, but not in my code, more strange that is doesn't default to the 20 second as specified in the documentation).

But to solve the problem, you need to set the CommandTimeOut on the command object itself before running the query rather than on the connection object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!