Skip to content

Commit 99e7324

Browse files
authored
Remove EndUserAction on pg error from ReadMessageLong (npgsql#4924)
1 parent 24f86ed commit 99e7324

11 files changed

+14
-23
lines changed

src/Npgsql/BackendMessages/AuthenticationMessages.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ sealed class AuthenticationMD5PasswordMessage : AuthenticationRequestMessage
4040
{
4141
internal override AuthenticationRequestType AuthRequestType => AuthenticationRequestType.AuthenticationMD5Password;
4242

43-
internal byte[] Salt { get; private set; }
43+
internal byte[] Salt { get; }
4444

4545
internal static AuthenticationMD5PasswordMessage Load(NpgsqlReadBuffer buf)
4646
{
@@ -75,7 +75,7 @@ sealed class AuthenticationGSSContinueMessage : AuthenticationRequestMessage
7575
{
7676
internal override AuthenticationRequestType AuthRequestType => AuthenticationRequestType.AuthenticationGSSContinue;
7777

78-
internal byte[] AuthenticationData { get; private set; }
78+
internal byte[] AuthenticationData { get; }
7979

8080
internal static AuthenticationGSSContinueMessage Load(NpgsqlReadBuffer buf, int len)
8181
{

src/Npgsql/BackendMessages/BackendKeyDataMessage.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ sealed class BackendKeyDataMessage : IBackendMessage
66
{
77
public BackendMessageCode Code => BackendMessageCode.BackendKeyData;
88

9-
internal int BackendProcessId { get; private set; }
10-
internal int BackendSecretKey { get; private set; }
9+
internal int BackendProcessId { get; }
10+
internal int BackendSecretKey { get; }
1111

1212
internal BackendKeyDataMessage(NpgsqlReadBuffer buf)
1313
{

src/Npgsql/Internal/NpgsqlConnector.cs

-6
Original file line numberDiff line numberDiff line change
@@ -1307,8 +1307,6 @@ internal ValueTask<IBackendMessage> ReadMessage(
13071307
case BackendMessageCode.ErrorResponse:
13081308
ReadBuffer.ReadPosition--;
13091309
return ReadMessageLong(async, dataRowLoadingMode, readingNotifications: false)!;
1310-
case BackendMessageCode.ReadyForQuery:
1311-
break;
13121310
}
13131311

13141312
PGUtil.ValidateBackendMessageCode(messageCode);
@@ -1444,10 +1442,6 @@ internal ValueTask<IBackendMessage> ReadMessage(
14441442
}
14451443
catch (PostgresException e)
14461444
{
1447-
// TODO: move it up the stack, like #3126 did (relevant for non-command-execution scenarios, like COPY)
1448-
if (CurrentReader is null)
1449-
EndUserAction();
1450-
14511445
if (e.SqlState == PostgresErrorCodes.QueryCanceled && PostgresCancellationPerformed)
14521446
{
14531447
// The query could be canceled because of a user cancellation or a timeout - raise the proper exception.

src/Npgsql/Internal/TypeHandling/TypeMappingInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Npgsql.Internal.TypeHandling;
77

8-
public class TypeMappingInfo
8+
public sealed class TypeMappingInfo
99
{
1010
public TypeMappingInfo(NpgsqlDbType? npgsqlDbType, string? dataTypeName, Type clrType)
1111
=> (NpgsqlDbType, DataTypeName, ClrTypes) = (npgsqlDbType, dataTypeName, new[] { clrType });

src/Npgsql/NameTranslation/NpgsqlNullNameTranslator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Npgsql.NameTranslation;
55
/// <summary>
66
/// A name translator which preserves CLR names (e.g. SomeClass) when mapping names to the database.
77
/// </summary>
8-
public class NpgsqlNullNameTranslator : INpgsqlNameTranslator
8+
public sealed class NpgsqlNullNameTranslator : INpgsqlNameTranslator
99
{
1010
/// <summary>
1111
/// Given a CLR type name (e.g class, struct, enum), translates its name to a database type name.

src/Npgsql/NameTranslation/NpgsqlSnakeCaseNameTranslator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Npgsql.NameTranslation;
99
/// A name translator which converts standard CLR names (e.g. SomeClass) to snake-case database
1010
/// names (some_class)
1111
/// </summary>
12-
public class NpgsqlSnakeCaseNameTranslator : INpgsqlNameTranslator
12+
public sealed class NpgsqlSnakeCaseNameTranslator : INpgsqlNameTranslator
1313
{
1414
/// <summary>
1515
/// Creates a new <see cref="NpgsqlSnakeCaseNameTranslator"/>.

src/Npgsql/NpgsqlBinaryImporter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ async ValueTask CloseAsync(bool async, CancellationToken cancellationToken = def
551551
throw new Exception("Invalid state: " + _state);
552552
}
553553

554-
_connector.EndUserAction();
555554
Cleanup();
556555
}
557556

@@ -566,8 +565,9 @@ void Cleanup()
566565

567566
if (connector != null)
568567
{
568+
connector.EndUserAction();
569569
connector.CurrentCopyOperation = null;
570-
_connector.Connection?.EndBindingScope(ConnectorBindingScope.Copy);
570+
connector.Connection?.EndBindingScope(ConnectorBindingScope.Copy);
571571
_connector = null;
572572
}
573573

src/Npgsql/NpgsqlDataSource.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public abstract class NpgsqlDataSource : DbDataSource
4141
/// <summary>
4242
/// Information about PostgreSQL and PostgreSQL-like databases (e.g. type definitions, capabilities...).
4343
/// </summary>
44-
internal NpgsqlDatabaseInfo DatabaseInfo { get; set; } = null!; // Initialized at bootstrapping
44+
internal NpgsqlDatabaseInfo DatabaseInfo { get; private set; } = null!; // Initialized at bootstrapping
4545

4646
internal Func<NpgsqlConnector, SslMode, NpgsqlTimeout, bool, bool, Task>? EncryptionNegotiator { get; }
4747
internal RemoteCertificateValidationCallback? UserCertificateValidationCallback { get; }

src/Npgsql/NpgsqlRawCopyStream.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ async Task Cancel(bool async)
372372
}
373373
catch (PostgresException e)
374374
{
375-
_connector.EndUserAction();
376375
Cleanup();
377376

378377
if (e.SqlState != PostgresErrorCodes.QueryCanceled)
@@ -442,7 +441,6 @@ async ValueTask DisposeAsync(bool disposing, bool async)
442441
}
443442
finally
444443
{
445-
_connector.EndUserAction();
446444
Cleanup();
447445
}
448446
}
@@ -452,6 +450,7 @@ void Cleanup()
452450
{
453451
Debug.Assert(!_isDisposed);
454452
LogMessages.CopyOperationCompleted(_copyLogger, _connector.Id);
453+
_connector.EndUserAction();
455454
_connector.CurrentCopyOperation = null;
456455
_connector.Connection?.EndBindingScope(ConnectorBindingScope.Copy);
457456
_connector = null;

src/Npgsql/NpgsqlTypes/PgNameAttribute.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ public class PgNameAttribute : Attribute
1818
/// <summary>
1919
/// The name of PostgreSQL field that corresponds to this CLR property or field
2020
/// </summary>
21-
public string PgName { get; private set; }
21+
public string PgName { get; }
2222

2323
/// <summary>
2424
/// Indicates that this property or field corresponds to a PostgreSQL field with the specified name
2525
/// </summary>
2626
/// <param name="pgName">The name of PostgreSQL field that corresponds to this CLR property or field</param>
2727
public PgNameAttribute(string pgName)
28-
{
29-
PgName = pgName;
30-
}
28+
=> PgName = pgName;
3129
}

src/Npgsql/Util/PGUtil.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static Statics()
2525
LegacyTimestampBehavior = AppContext.TryGetSwitch("Npgsql.EnableLegacyTimestampBehavior", out var enabled) && enabled;
2626
DisableDateTimeInfinityConversions = AppContext.TryGetSwitch("Npgsql.DisableDateTimeInfinityConversions", out enabled) && enabled;
2727
}
28-
28+
2929
internal static T Expect<T>(IBackendMessage msg, NpgsqlConnector connector)
3030
{
3131
if (msg.GetType() != typeof(T))

0 commit comments

Comments
 (0)