question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiplexing: ConnectorTypeMapping isn't thread-safe (since preview5)

See original GitHub issue

TypeMapping seems very broken since preview 5

     System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
         at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
         at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
         at Npgsql.TypeMapping.ConnectorTypeMapper.Bind(NpgsqlTypeHandler handler, PostgresType pgType, Nullable`1 npgsqlDbType, Type[] clrTypes)
         at Npgsql.TypeMapping.ConnectorTypeMapper.Bind(NpgsqlTypeMapping mapping, PostgresType pgType)
         at Npgsql.TypeMapping.ConnectorTypeMapper.BindArray(NpgsqlTypeMapping elementMapping)
         at Npgsql.TypeMapping.ConnectorTypeMapper.GetByClrType(Type type)
         at Npgsql.NpgsqlParameter.ResolveHandler(ConnectorTypeMapper typeMapper)
         at Npgsql.NpgsqlCommand.ValidateParameters(ConnectorTypeMapper typeMapper)
         at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
         at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
         at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
System.IndexOutOfRangeException: Index was outside the bounds of the array.
         at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
         at Npgsql.TypeMapping.ConnectorTypeMapper.Bind(NpgsqlTypeHandler handler, PostgresType pgType, Nullable`1 npgsqlDbType, Type[] clrTypes)
         at Npgsql.TypeMapping.ConnectorTypeMapper.Bind(NpgsqlTypeMapping mapping, PostgresType pgType)
         at Npgsql.TypeMapping.ConnectorTypeMapper.BindArray(NpgsqlTypeMapping elementMapping)
         at Npgsql.TypeMapping.ConnectorTypeMapper.GetByClrType(Type type)
         at Npgsql.NpgsqlParameter.ResolveHandler(ConnectorTypeMapper typeMapper)
         at Npgsql.NpgsqlCommand.ValidateParameters(ConnectorTypeMapper typeMapper)
         at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
         at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
         at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)

and other fun manifestations of concurrent inits. preview4 is ok so it must be one of the AOT preparation PRs that caused this.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
vonzshikcommented, Jul 6, 2021

Yeah, I found the problem - MultiplexingConnectorPool.MultiplexingTypeMapper is used by every command on the same pool, and since ConnectorTypeMapper isn’t thread safe…

0reactions
rojicommented, Jul 15, 2021

As discussed offline, we should try to avoid having another TypeMapper just for multiplexing - just using ConcurrentDictionary in ConnectorTypeMapper may be good enough (also need to pay attention to racing bindings)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prove that HashMap in java is not thread-safe
A hash map is based on an array, where each item represents a bucket. ... So theoretically it is proven that HashMap is...
Read more >
Ensuring the thread-safety of the entire codebase : r/java
I just encountered a bug where my non-thread safe cache implementation caused race conditions due to a piece of code way up the...
Read more >
What Is Thread-Safety and How to Achieve It?
This means that different threads can access the same resources without exposing erroneous behavior or producing unpredictable results.
Read more >
Lettuce Reference Guide
Lettuce is a scalable thread-safe Redis client based on netty and Reactor. Lettuce provides synchronous, asynchronous and reactive APIs to interact with Redis....
Read more >
Changelog
BUILD: cfgparse: Fix GCC warning about a variable used after realloc ... reads too far when no port nor path - BUG/MEDIUM: mux-h1:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found