Reading bit value goes into an infinity loop
See original GitHub issueWhen reading a bit type value, I encountered a bug that caused an infinite loop under certain conditions.
Steps to reproduce
using (var conn = new NpgsqlConnection(connnectionString))
{
conn.Open();
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = @"SELECT 1::bit(100000);";
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
{
reader.Read();
reader.GetValue(0); // infinite loop!!
}
}
}
The issue
BitStringHandler
has the cause. In case a bit value cuts across a buffer boundary, the last byte will never read and result in an infinite loop. The buf.ReadBytesLeft
property remains at 1 and the loop cannot be escaped.
Above example is terrible, but our application is facing same problem. It reads 16-bit column values, and cuts across a buffer boundary depending on the data state.
If I set CommandBehavior
to default, it works. but we use Dapper, and Dapper’s Query method internally sets CommandBehavior.SequentialAccess
link.
Further technical details
Npgsql version: 4.1.2 PostgreSQL version: 9.6 Operating system: Windows 10
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
my loop goes to an endless loop. How can I solve it? ...
The code successfully parses 123 into an integer, and assigns it to input . No infinite loop, the program has completed. System.in: scan:...
Read more >What is an infinite loop (endless loop)?
An infinite loop is piece of coding that repeats itself indefinitely. Learn how it works and when it can be useful or harmful...
Read more >Infinite loop when entering a character? - C++ Forum
Is that a random memory address? I went back to the loop I made and entered the value -858993460 when asked to enter...
Read more >Best way to track down infinite loop?
I've gotten MonoDevelop to stop infinite loops. Just switch to MD, start debugging, and press "Pause". It'll stop you somewhere in the infinite ......
Read more >How to Find the Exact Line of an Infinite Loop Bug in the code
It's a bit tricky to find and you might spend some time to know why it's happening but the good thing is you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Would like, but without a rush. Am out of the city till tomorrow (:
@YohDeadfall Aha that makes sense, thanks!