Skip to content

Commit 4bd4115

Browse files
committed
Multiplexing and pool rewrite
1 parent cb2cf5d commit 4bd4115

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+5500
-3938
lines changed

.github/workflows/build.yml

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ jobs:
4141
sudo apt-get install -qq postgresql-${{ matrix.pg_major }} postgresql-${{ matrix.pg_major }}-postgis-${{ env.postgis_version }}
4242
sudo -u postgres psql -c "CREATE USER npgsql_tests SUPERUSER PASSWORD 'npgsql_tests'"
4343
sudo -u postgres psql -c "CREATE DATABASE npgsql_tests OWNER npgsql_tests"
44+
sudo -u postgres psql -c "CREATE EXTENSION postgis" npgsql_tests
45+
sudo -u postgres psql -c "CREATE EXTENSION hstore" npgsql_tests
46+
sudo -u postgres psql -c "CREATE EXTENSION citext" npgsql_tests
4447
4548
export PGDATA=/etc/postgresql/${{ matrix.pg_major }}/main
4649
sudo sed -i 's/#ssl = off/ssl = on/' $PGDATA/postgresql.conf
@@ -91,6 +94,9 @@ jobs:
9194
# Configure test account
9295
pgsql/bin/psql -U postgres -c "CREATE ROLE npgsql_tests SUPERUSER LOGIN PASSWORD 'npgsql_tests'"
9396
pgsql/bin/psql -U postgres -c "CREATE DATABASE npgsql_tests OWNER npgsql_tests"
97+
pgsql/bin/psql -U postgres -c "CREATE EXTENSION postgis" npgsql_tests
98+
pgsql/bin/psql -U postgres -c "CREATE EXTENSION hstore" npgsql_tests
99+
pgsql/bin/psql -U postgres -c "CREATE EXTENSION citext" npgsql_tests
94100
95101
# Disable trust authentication, requiring MD5 passwords - some tests must fail if a password isn't provided.
96102
echo "host all all all md5" > pgsql/PGDATA/pg_hba.conf

src/Npgsql/ConnectorPool.Multiplexing.cs

+429
Large diffs are not rendered by default.

src/Npgsql/ConnectorPool.cs

+320-417
Large diffs are not rendered by default.

src/Npgsql/Npgsql.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<PackageTags>npgsql postgresql postgres ado ado.net database sql</PackageTags>
66
<!-- At this point we target netcoreapp3.0 to avoid taking a dependency on System.Text.Json, which is
77
necessary for all other TFMs. -->
8-
<TargetFrameworks>netcoreapp5.0</TargetFrameworks>
8+
<TargetFrameworks>netcoreapp3.0</TargetFrameworks>
99
<TargetFrameworks Condition="'$(DeveloperBuild)' != 'True'">net461;netstandard2.0;netstandard2.1;netcoreapp3.0</TargetFrameworks>
1010
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1111
</PropertyGroup>
@@ -24,5 +24,6 @@
2424
</ItemGroup>
2525
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' OR '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1' ">
2626
<PackageReference Include="System.Text.Json" Version="4.6.0" />
27+
<PackageReference Include="System.Threading.Channels" Version="4.7.0" />
2728
</ItemGroup>
2829
</Project>

src/Npgsql/NpgsqlBinaryExporter.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ internal NpgsqlBinaryExporter(NpgsqlConnector connector, string copyToCommand)
5959
copyOutResponse = (CopyOutResponseMessage)msg;
6060
if (!copyOutResponse.IsBinary)
6161
{
62-
_connector.Break();
63-
throw new ArgumentException("copyToCommand triggered a text transfer, only binary is allowed", nameof(copyToCommand));
62+
throw _connector.Break(
63+
new ArgumentException("copyToCommand triggered a text transfer, only binary is allowed",
64+
nameof(copyToCommand)));
6465
}
6566
break;
6667
case BackendMessageCode.CompletedResponse:
@@ -281,9 +282,9 @@ async ValueTask<T> DoRead<T>(NpgsqlTypeHandler handler, bool async)
281282
_column++;
282283
return result;
283284
}
284-
catch
285+
catch (Exception e)
285286
{
286-
_connector.Break();
287+
_connector.Break(e);
287288
Cleanup();
288289
throw;
289290
}
@@ -400,6 +401,7 @@ void Cleanup()
400401
if (connector != null)
401402
{
402403
connector.CurrentCopyOperation = null;
404+
_connector.Connection?.EndBindingScope(ConnectorBindingScope.Copy);
403405
_connector = null;
404406
}
405407

src/Npgsql/NpgsqlBinaryImporter.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ internal NpgsqlBinaryImporter(NpgsqlConnector connector, string copyFromCommand)
6363
copyInResponse = (CopyInResponseMessage)msg;
6464
if (!copyInResponse.IsBinary)
6565
{
66-
_connector.Break();
67-
throw new ArgumentException("copyFromCommand triggered a text transfer, only binary is allowed", nameof(copyFromCommand));
66+
throw _connector.Break(
67+
new ArgumentException("copyFromCommand triggered a text transfer, only binary is allowed",
68+
nameof(copyFromCommand)));
6869
}
6970
break;
7071
case BackendMessageCode.CompletedResponse:
@@ -448,8 +449,8 @@ async Task Cancel(bool async)
448449
{
449450
var msg = await _connector.ReadMessage(async);
450451
// The CopyFail should immediately trigger an exception from the read above.
451-
_connector.Break();
452-
throw new NpgsqlException("Expected ErrorResponse when cancelling COPY but got: " + msg.Code);
452+
throw _connector.Break(
453+
new NpgsqlException("Expected ErrorResponse when cancelling COPY but got: " + msg.Code));
453454
}
454455
catch (PostgresException e)
455456
{
@@ -508,6 +509,7 @@ void Cleanup()
508509
if (connector != null)
509510
{
510511
connector.CurrentCopyOperation = null;
512+
_connector.Connection?.EndBindingScope(ConnectorBindingScope.Copy);
511513
_connector = null;
512514
}
513515

0 commit comments

Comments
 (0)