Sometimes: Object Null Exception when using var rdr = await cmd.ExecuteReaderAsync();
The cmd.ExecuteReaderAsync sometimes get NullException.
Source:
public async Task<GetNavigationBarBulletsContent> Get([FromServices] MySqlDataSource dbBroadcast )
{
await using var conn = await dbBroadcast.OpenConnectionAsync();
string qChannelsToScan = "SELECT channel_id FROM channels_members WHERE member_id = @my_id";
using var cmdChannelsToScan = new MySqlCommand(qChannelsToScan, conn);
cmdChannelsToScan.Parameters.AddWithValue("my_id", internal_id);
using var rdrChannelsToScan = await cmdChannelsToScan.ExecuteReaderAsync(); // Here is the NullException thrown
}
13 Replies
This happens in around 1% of the cases. I hoped to use a MySQLDataSource dependency injection would help, but it did not.
In most cases, after this primary error, i got
MySqlConnector.MySqlProtocolException: Packet received out-of-order. Expected 1; got 2.
either which took my thinking it has a connectionpool problem. Unfortunately it didn't solve the case.use
```cs
// code here
```
To format code
aha i see, new for me 🙂 thanks
What is the type of internal_id
You should also not be making a new connection per call
Perhaps you are hitting an upper connection limit?
I dont think on the first line of the function needs a second await
long
therefor i tried to use the dependency injection, but no improvement. Besides that, the MySqlConnector keeps a pool of connections available anyway and re-uses that with the OpenConnection command.. So it also doesn't make sense there i think
myeah something like that would be it.. But can't see it as nowhere are signs of that for the rest. All other APIs / calls programs / connections etc are just fine. It looks like the system gets confused, especially with often hitting the second error that it expected more packets (
MySqlConnector.MySqlProtocolException: Packet received out-of-order. Expected 1; got 2
) So it expects results on 1 query but gets another result, it seems.
you are right, that first await can be ditched. using var
will be enough.You need to make sure that
internal_id
is never null
, which is probably what causes your NRE at that line.
Side-note: Don't use MySQL, it's bad 👀i could test that but pretty sure it cant be null as prelim code would already crash on that point
what do you advice mr SB?
PostgreSQL
Both faster, more secure and with far more features than MySQL could even dream of ever having.
aight sounds good, will check it later on. for now i have a 1% unstable connectionpool bothering users hehe
Postgresql is a good one. I like mongodb personally.
If you don't like to think of pesky things like "schema", "type safety", or "data integrity" then yes, Mongo is a choice
Personally, I don't like and I don't generally recommend NoSQL databases, unless you have a very specific use-case which modern RDBMS don't provide for you.
I have yet to find such use-cases.
Because any requirements I had did not necessitate a NoSQL database.
Plus there's stuff like this https://thehackernews.com/2023/12/mongodb-suffers-security-breach.html
The Hacker News
MongoDB Suffers Security Breach, Exposing Customer Data
A security incident at MongoDB has led to unauthorized access to corporate systems, compromising customer account info.