-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Random errors occurring during concurrent database access. #1133
Comments
Hi, thanks for reporting this issue. Ideally, the library should be thread-safe by design, but this is a good catch if you encountered it to be not. Sounds like other threads are contaminating the cache of other threads? It is a bit tricky to replicate TBH, but we will get back to you once replicated and if we have possible solutions. |
To generalize the first "prewarm", i place that method into an Init-Method within inherited
This works, but QueryAll is what it means, it pulls the whole Table. Query() does not work, because it requires the TEntity this does not work:
this works:
Is this the correct way? |
Here's another exception (happens only when using multiple Threads):
|
Maybe it's useful: It seems it has todo with the PropertyHandlers. They are all declared at Property Level, but it seems they are sometimes not correctly respected. public class FooClass : IdModelBase
{
[PropertyHandler(typeof(JsonPropertyHandler))]
[NpgsqlDbType(NpgsqlTypes.NpgsqlDbType.Jsonb)]
public Translation Name { get; set; }
}
public class JsonPropertyHandler : IPropertyHandler<string?, object?>
{
public object? Get(string? input, PropertyHandlerGetOptions options)
{
if (!string.IsNullOrEmpty(input))
return JsonConvert.DeserializeObject(input, options.ClassProperty.PropertyInfo.PropertyType);
return null;
}
public string? Set(object? input, PropertyHandlerSetOptions options)
{
if (input != null)
return JsonHelper.ToString(input);
return null;
}
} Again, the behavior only happens when using concurrent connections. |
@arakis FWIW, we came across this exact issue too. The fact you filed this issue gave me the determination to debug RepoDb when the issue seemed very elusive! Thank you and hope the PR helps. |
Bug Description
I am using a single BaseRepository instance across multiple threads. As long as I make a "prewarm" single-threaded call, all other parallel queries work without issue. However, without a "prewarm," I run into random errors. The errors occur seemingly at random, such as DateOnly cannot being converted to DateTime, DbNull versus non-DbNull, and so on. It seems there may be a problem while initializing the mapper (I am not using any cache or mapper of my own, I simply use the BaseRepository without any arguments other than the connection string).
I have called PostgreSqlBootstrap.Initialize before, and I ensure that it is called only once.
Question: What is the correct way to handle concurrent queries?
Exception Message:
Library Version:
Example: RepoDb v1.13 and RepoDb.Postgres v1.13
The text was updated successfully, but these errors were encountered: