| | | 1 | | using Microsoft.Data.SqlClient; |
| | | 2 | | using System.Data; |
| | | 3 | | |
| | | 4 | | namespace AsyncResponse.Channels.SqlServer; |
| | | 5 | | |
| | | 6 | | internal readonly record struct SqlServerChannelMessage( |
| | | 7 | | Guid Id, |
| | | 8 | | string CorrelationId, |
| | | 9 | | string EnvelopeJson, |
| | | 10 | | DateTimeOffset CreatedAtUtc, |
| | | 11 | | DateTimeOffset? AckedAtUtc = null); |
| | | 12 | | |
| | | 13 | | /// <summary>SQL helper for the SQL Server channel tables.</summary> |
| | | 14 | | internal sealed class SqlServerChannelSql |
| | | 15 | | { |
| | | 16 | | // SQL Server duplicate-key error numbers: 2627 = PRIMARY KEY/UNIQUE constraint violation, |
| | | 17 | | // 2601 = unique index violation. Retried idempotent inserts treat them as success. |
| | | 18 | | private const int PrimaryKeyViolation = 2627; |
| | | 19 | | private const int UniqueIndexViolation = 2601; |
| | | 20 | | |
| | | 21 | | private readonly string _connectionString; |
| | | 22 | | private readonly SqlServerAsyncResponseChannelOptions _options; |
| | 3 | 23 | | private readonly SemaphoreSlim _ensureGate = new(1, 1); |
| | | 24 | | private bool _created; |
| | | 25 | | private long _lastRecoveryPruneTicks; |
| | | 26 | | private long _lastMessagePruneTicks; |
| | | 27 | | private long _lastSubscriberPruneTicks; |
| | | 28 | | |
| | 3 | 29 | | public SqlServerChannelSql(Microsoft.Extensions.Options.IOptions<SqlServerAsyncResponseChannelOptions> options) |
| | | 30 | | { |
| | 3 | 31 | | _options = options.Value; |
| | 3 | 32 | | _options.Validate(); |
| | 3 | 33 | | _connectionString = _options.ConnectionString!; |
| | | 34 | | |
| | 3 | 35 | | Schema = Quote(_options.SchemaName); |
| | 3 | 36 | | RecoveryTable = $"{Schema}.{Quote(_options.RecoveryStateTable)}"; |
| | 3 | 37 | | MessageTable = $"{Schema}.{Quote(_options.MessageTable)}"; |
| | 3 | 38 | | SubscriberTable = $"{Schema}.{Quote(_options.SubscriberTable)}"; |
| | 3 | 39 | | } |
| | | 40 | | |
| | | 41 | | public string Schema { get; } |
| | | 42 | | public string RecoveryTable { get; } |
| | | 43 | | public string MessageTable { get; } |
| | | 44 | | public string SubscriberTable { get; } |
| | | 45 | | |
| | | 46 | | public async Task EnsureCreatedAsync(CancellationToken cancellationToken = default) |
| | | 47 | | { |
| | 3 | 48 | | if (_created || !_options.AutoCreateSchema) |
| | 3 | 49 | | return; |
| | | 50 | | |
| | 3 | 51 | | await _ensureGate.WaitAsync(cancellationToken).ConfigureAwait(false); |
| | | 52 | | try |
| | | 53 | | { |
| | 3 | 54 | | if (_created) |
| | 1 | 55 | | return; |
| | | 56 | | |
| | 3 | 57 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 58 | | await using var transaction = (SqlTransaction)await connection.BeginTransactionAsync(cancellationToken).Conf |
| | | 59 | | |
| | | 60 | | // Serialize schema creation across processes. The IF-NOT-EXISTS guards are not atomic |
| | | 61 | | // against a concurrent create of the same object: two instances starting together both |
| | | 62 | | // pass the existence check and collide on the catalog (error 2714/2627). A |
| | | 63 | | // transaction-scoped application lock (keyed by schema, shared with the transport store) |
| | | 64 | | // lets one instance build the schema while the rest wait and then find it already present. |
| | 1 | 65 | | await using (var lockCommand = connection.CreateCommand()) |
| | | 66 | | { |
| | 1 | 67 | | lockCommand.Transaction = transaction; |
| | 1 | 68 | | lockCommand.CommandText = |
| | 1 | 69 | | """ |
| | 1 | 70 | | DECLARE @lock_result int; |
| | 1 | 71 | | EXEC @lock_result = sp_getapplock |
| | 1 | 72 | | @Resource = @lock_resource, |
| | 1 | 73 | | @LockMode = 'Exclusive', |
| | 1 | 74 | | @LockOwner = 'Transaction', |
| | 1 | 75 | | @LockTimeout = 60000; |
| | 1 | 76 | | IF @lock_result < 0 |
| | 1 | 77 | | THROW 51000, N'Failed to acquire the AsyncResponse DDL application lock.', 1; |
| | 1 | 78 | | """; |
| | 1 | 79 | | lockCommand.Parameters.AddWithValue("@lock_resource", SchemaLockResource(_options.SchemaName)); |
| | 1 | 80 | | await lockCommand.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); |
| | | 81 | | } |
| | | 82 | | |
| | 1 | 83 | | await using var command = connection.CreateCommand(); |
| | 1 | 84 | | command.Transaction = transaction; |
| | 1 | 85 | | command.CommandText = |
| | 1 | 86 | | $""" |
| | 1 | 87 | | IF SCHEMA_ID(N'{_options.SchemaName}') IS NULL |
| | 1 | 88 | | EXEC(N'CREATE SCHEMA {Schema}'); |
| | 1 | 89 | | |
| | 1 | 90 | | IF OBJECT_ID(N'{RecoveryTable}', N'U') IS NULL |
| | 1 | 91 | | CREATE TABLE {RecoveryTable} ( |
| | 1 | 92 | | correlation_id nvarchar(400) NOT NULL, |
| | 1 | 93 | | registration_id uniqueidentifier NOT NULL, |
| | 1 | 94 | | state_json nvarchar(max) NOT NULL, |
| | 1 | 95 | | expires_at datetime2 NOT NULL, |
| | 1 | 96 | | registered_at datetime2 NOT NULL DEFAULT SYSUTCDATETIME(), |
| | 1 | 97 | | PRIMARY KEY (correlation_id, registration_id) |
| | 1 | 98 | | ); |
| | 1 | 99 | | IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'{IndexName(_options.RecoveryStateTable, "expires |
| | 1 | 100 | | CREATE INDEX {Quote(IndexName(_options.RecoveryStateTable, "expires"))} |
| | 1 | 101 | | ON {RecoveryTable} (expires_at); |
| | 1 | 102 | | |
| | 1 | 103 | | IF OBJECT_ID(N'{MessageTable}', N'U') IS NULL |
| | 1 | 104 | | CREATE TABLE {MessageTable} ( |
| | 1 | 105 | | id uniqueidentifier NOT NULL PRIMARY KEY NONCLUSTERED, |
| | 1 | 106 | | correlation_id nvarchar(400) NOT NULL, |
| | 1 | 107 | | envelope_json nvarchar(max) NOT NULL, |
| | 1 | 108 | | created_at datetime2 NOT NULL DEFAULT SYSUTCDATETIME(), |
| | 1 | 109 | | expires_at datetime2 NOT NULL, |
| | 1 | 110 | | acked_at datetime2 NULL, |
| | 1 | 111 | | recovery_claimed bit NOT NULL DEFAULT 0 |
| | 1 | 112 | | ); |
| | 1 | 113 | | IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'{IndexName(_options.MessageTable, "correlation_c |
| | 1 | 114 | | CREATE INDEX {Quote(IndexName(_options.MessageTable, "correlation_created"))} |
| | 1 | 115 | | ON {MessageTable} (correlation_id, created_at); |
| | 1 | 116 | | IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'{IndexName(_options.MessageTable, "expires")}' A |
| | 1 | 117 | | CREATE INDEX {Quote(IndexName(_options.MessageTable, "expires"))} |
| | 1 | 118 | | ON {MessageTable} (expires_at); |
| | 1 | 119 | | |
| | 1 | 120 | | IF OBJECT_ID(N'{SubscriberTable}', N'U') IS NULL |
| | 1 | 121 | | CREATE TABLE {SubscriberTable} ( |
| | 1 | 122 | | correlation_id nvarchar(400) NOT NULL, |
| | 1 | 123 | | registration_id uniqueidentifier NOT NULL, |
| | 1 | 124 | | instance_id nvarchar(200) NOT NULL, |
| | 1 | 125 | | expires_at datetime2 NOT NULL, |
| | 1 | 126 | | PRIMARY KEY (correlation_id, registration_id) |
| | 1 | 127 | | ); |
| | 1 | 128 | | IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'{IndexName(_options.SubscriberTable, "expires")} |
| | 1 | 129 | | CREATE INDEX {Quote(IndexName(_options.SubscriberTable, "expires"))} |
| | 1 | 130 | | ON {SubscriberTable} (expires_at); |
| | 1 | 131 | | """; |
| | 1 | 132 | | await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 133 | | await transaction.CommitAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 134 | | _created = true; |
| | 1 | 135 | | } |
| | | 136 | | finally |
| | | 137 | | { |
| | 3 | 138 | | _ensureGate.Release(); |
| | | 139 | | } |
| | 3 | 140 | | } |
| | | 141 | | |
| | | 142 | | public async Task SaveRecoveryStateAsync(string correlationId, RecoveryState state, TimeSpan ttl, CancellationToken |
| | | 143 | | { |
| | 3 | 144 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 3 | 145 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 146 | | await using var command = connection.CreateCommand(); |
| | | 147 | | // MERGE WITH (HOLDLOCK) makes the match check and insert atomic — the SQL Server equivalent |
| | | 148 | | // of PostgreSQL's INSERT ... ON CONFLICT DO UPDATE for the (correlation_id, registration_id) key. |
| | 1 | 149 | | command.CommandText = |
| | 1 | 150 | | $""" |
| | 1 | 151 | | MERGE {RecoveryTable} WITH (HOLDLOCK) AS target |
| | 1 | 152 | | USING (SELECT @correlation_id AS correlation_id, @registration_id AS registration_id) AS source |
| | 1 | 153 | | ON target.correlation_id = source.correlation_id AND target.registration_id = source.registration_id |
| | 1 | 154 | | WHEN MATCHED THEN |
| | 1 | 155 | | UPDATE SET state_json = @state_json, |
| | 1 | 156 | | expires_at = {AddMilliseconds("@ttl_ms")}, |
| | 1 | 157 | | registered_at = SYSUTCDATETIME() |
| | 1 | 158 | | WHEN NOT MATCHED THEN |
| | 1 | 159 | | INSERT (correlation_id, registration_id, state_json, expires_at, registered_at) |
| | 1 | 160 | | VALUES (@correlation_id, @registration_id, @state_json, {AddMilliseconds("@ttl_ms")}, SYSUTCDATETIME()); |
| | 1 | 161 | | """; |
| | 1 | 162 | | command.Parameters.AddWithValue("@correlation_id", correlationId); |
| | 1 | 163 | | command.Parameters.AddWithValue("@registration_id", state.RegistrationId); |
| | 1 | 164 | | command.Parameters.AddWithValue("@state_json", AsyncResponseJson.Serialize(state)); |
| | 1 | 165 | | command.Parameters.AddWithValue("@ttl_ms", (long)ttl.TotalMilliseconds); |
| | 1 | 166 | | await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 167 | | } |
| | | 168 | | |
| | | 169 | | public async Task<IReadOnlyList<string>> LoadRecoveryStatesAsync(string correlationId, CancellationToken cancellatio |
| | | 170 | | { |
| | 1 | 171 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 172 | | if (ShouldPrune(ref _lastRecoveryPruneTicks)) |
| | 1 | 173 | | await PruneExpiredRecoveryAsync(correlationId, cancellationToken).ConfigureAwait(false); |
| | | 174 | | |
| | 1 | 175 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 176 | | await using var command = connection.CreateCommand(); |
| | 1 | 177 | | command.CommandText = |
| | 1 | 178 | | $""" |
| | 1 | 179 | | SELECT state_json |
| | 1 | 180 | | FROM {RecoveryTable} |
| | 1 | 181 | | WHERE correlation_id = @correlation_id AND expires_at > SYSUTCDATETIME() |
| | 1 | 182 | | ORDER BY registered_at; |
| | 1 | 183 | | """; |
| | 1 | 184 | | command.Parameters.AddWithValue("@correlation_id", correlationId); |
| | | 185 | | |
| | 1 | 186 | | var states = new List<string>(); |
| | 1 | 187 | | await using var reader = await command.ExecuteReaderAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 188 | | while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false)) |
| | 1 | 189 | | states.Add(reader.GetString(0)); |
| | 1 | 190 | | return states; |
| | 1 | 191 | | } |
| | | 192 | | |
| | | 193 | | public async Task<bool> DeleteRecoveryStateAsync(string correlationId, Guid registrationId, CancellationToken cancel |
| | | 194 | | { |
| | 1 | 195 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 196 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 197 | | await using var command = connection.CreateCommand(); |
| | 1 | 198 | | command.CommandText = $"DELETE FROM {RecoveryTable} WHERE correlation_id = @correlation_id AND registration_id = |
| | 1 | 199 | | command.Parameters.AddWithValue("@correlation_id", correlationId); |
| | 1 | 200 | | command.Parameters.AddWithValue("@registration_id", registrationId); |
| | 1 | 201 | | return await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false) > 0; |
| | 1 | 202 | | } |
| | | 203 | | |
| | | 204 | | public async IAsyncEnumerable<string> ScanRecoveryStateJsonAsync([System.Runtime.CompilerServices.EnumeratorCancella |
| | | 205 | | { |
| | 1 | 206 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 207 | | await PruneExpiredRecoveryAsync(null, cancellationToken).ConfigureAwait(false); |
| | | 208 | | |
| | 1 | 209 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 210 | | await using var command = connection.CreateCommand(); |
| | 1 | 211 | | command.CommandText = |
| | 1 | 212 | | $""" |
| | 1 | 213 | | SELECT state_json |
| | 1 | 214 | | FROM {RecoveryTable} |
| | 1 | 215 | | WHERE expires_at > SYSUTCDATETIME() |
| | 1 | 216 | | ORDER BY registered_at; |
| | 1 | 217 | | """; |
| | 1 | 218 | | await using var reader = await command.ExecuteReaderAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 219 | | while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false)) |
| | 1 | 220 | | yield return reader.GetString(0); |
| | 1 | 221 | | } |
| | | 222 | | |
| | | 223 | | /// <summary> |
| | | 224 | | /// Inserts a response envelope row. The caller supplies the message id so the insert is |
| | | 225 | | /// idempotent under retry — a duplicate insert (lost WHERE NOT EXISTS race or an outer retry) |
| | | 226 | | /// is treated as success, so a retried publish never duplicates a response. Returns the row's |
| | | 227 | | /// server-stamped <c>created_at</c> (the original row's on a duplicate) so the same-process |
| | | 228 | | /// fast path compares against subscription watermarks on the server clock rather than the |
| | | 229 | | /// app clock. |
| | | 230 | | /// </summary> |
| | | 231 | | public Task<DateTimeOffset> InsertMessageAsync(Guid id, string correlationId, string envelopeJson, TimeSpan retentio |
| | 1 | 232 | | => AsyncResponseRetry.ExecuteAsync( |
| | 1 | 233 | | token => InsertMessageOnceAsync(id, correlationId, envelopeJson, retention, token), |
| | 1 | 234 | | IsTransient, |
| | 1 | 235 | | _options.PublishMaxAttempts, |
| | 1 | 236 | | _options.PublishRetryBaseDelay, |
| | 1 | 237 | | _options.PublishRetryMaxDelay, |
| | 1 | 238 | | cancellationToken); |
| | | 239 | | |
| | | 240 | | private async Task<DateTimeOffset> InsertMessageOnceAsync(Guid id, string correlationId, string envelopeJson, TimeSp |
| | | 241 | | { |
| | 1 | 242 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 243 | | if (ShouldPrune(ref _lastMessagePruneTicks)) |
| | 1 | 244 | | await PruneExpiredMessagesAsync(cancellationToken).ConfigureAwait(false); |
| | | 245 | | |
| | 1 | 246 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 247 | | await using var command = connection.CreateCommand(); |
| | 1 | 248 | | command.CommandText = |
| | 1 | 249 | | $""" |
| | 1 | 250 | | INSERT INTO {MessageTable} (id, correlation_id, envelope_json, expires_at) |
| | 1 | 251 | | OUTPUT inserted.created_at |
| | 1 | 252 | | SELECT @id, @correlation_id, @envelope_json, {AddMilliseconds("@retention_ms")} |
| | 1 | 253 | | WHERE NOT EXISTS (SELECT 1 FROM {MessageTable} WITH (UPDLOCK, HOLDLOCK) WHERE id = @id); |
| | 1 | 254 | | """; |
| | 1 | 255 | | command.Parameters.AddWithValue("@id", id); |
| | 1 | 256 | | command.Parameters.AddWithValue("@correlation_id", correlationId); |
| | 1 | 257 | | command.Parameters.AddWithValue("@envelope_json", envelopeJson); |
| | 1 | 258 | | command.Parameters.AddWithValue("@retention_ms", (long)retention.TotalMilliseconds); |
| | | 259 | | |
| | 1 | 260 | | object? createdAt = null; |
| | | 261 | | try |
| | | 262 | | { |
| | 1 | 263 | | createdAt = await command.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 264 | | } |
| | 0 | 265 | | catch (SqlException ex) when (ex.Number is PrimaryKeyViolation or UniqueIndexViolation) |
| | | 266 | | { |
| | 1 | 267 | | } |
| | | 268 | | |
| | 1 | 269 | | if (createdAt is DateTime insertedCreatedAt) |
| | 1 | 270 | | return new DateTimeOffset(insertedCreatedAt, TimeSpan.Zero); |
| | | 271 | | |
| | | 272 | | // Duplicate insert (WHERE NOT EXISTS suppressed it, or the key-violation race lost): |
| | | 273 | | // return the original row's server-stamped created_at. Unlike PostgreSQL's single-statement |
| | | 274 | | // CTE, this fallback is already a SEPARATE statement, so a concurrent same-id publish is |
| | | 275 | | // resolved here deterministically: the HOLDLOCK range lock on the first statement |
| | | 276 | | // serializes against the competing insert, and this second statement reads its own fresh |
| | | 277 | | // snapshot/locks and sees the committed row. |
| | 1 | 278 | | await using var lookup = connection.CreateCommand(); |
| | 1 | 279 | | lookup.CommandText = $"SELECT created_at FROM {MessageTable} WHERE id = @id;"; |
| | 1 | 280 | | lookup.Parameters.AddWithValue("@id", id); |
| | 1 | 281 | | var existing = await lookup.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false); |
| | | 282 | | |
| | | 283 | | // A missing row means the idempotent duplicate's original is already gone (pruned |
| | | 284 | | // mid-publish): the message is not persisted, so reporting success with a fabricated |
| | | 285 | | // app-clock timestamp would both lie about persistence and feed a client clock into the |
| | | 286 | | // server-clock watermark. Fail instead, so the publisher's error handling runs. |
| | 1 | 287 | | return existing is DateTime existingCreatedAt |
| | 1 | 288 | | ? new DateTimeOffset(existingCreatedAt, TimeSpan.Zero) |
| | 1 | 289 | | : throw new InvalidOperationException( |
| | 1 | 290 | | $"SQL Server response insert for message {id} found no row after a duplicate: the original no longer exi |
| | 1 | 291 | | } |
| | | 292 | | |
| | | 293 | | public async Task<IReadOnlyList<SqlServerChannelMessage>> LoadMessagesAsync( |
| | | 294 | | string correlationId, |
| | | 295 | | DateTimeOffset sinceUtc, |
| | | 296 | | int batchSize, |
| | | 297 | | DateTimeOffset? afterCreatedAtUtc, |
| | | 298 | | Guid? afterId, |
| | | 299 | | CancellationToken cancellationToken) |
| | | 300 | | { |
| | 3 | 301 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 3 | 302 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 303 | | await using var command = connection.CreateCommand(); |
| | 1 | 304 | | command.CommandText = |
| | 1 | 305 | | $""" |
| | 1 | 306 | | SELECT id, correlation_id, envelope_json, created_at, acked_at |
| | 1 | 307 | | FROM {MessageTable} |
| | 1 | 308 | | WHERE correlation_id = @correlation_id |
| | 1 | 309 | | AND created_at >= @since |
| | 1 | 310 | | AND expires_at > SYSUTCDATETIME() |
| | 1 | 311 | | {(afterCreatedAtUtc is null ? "" : "AND (created_at > @after_created_at OR (created_at = @after_created_at |
| | 1 | 312 | | ORDER BY created_at, id |
| | 1 | 313 | | OFFSET 0 ROWS FETCH NEXT @limit ROWS ONLY; |
| | 1 | 314 | | """; |
| | 1 | 315 | | command.Parameters.AddWithValue("@correlation_id", correlationId); |
| | 1 | 316 | | var sinceParameter = command.Parameters.Add("@since", SqlDbType.DateTime2); |
| | 1 | 317 | | sinceParameter.Scale = 7; |
| | 1 | 318 | | sinceParameter.Value = sinceUtc.UtcDateTime; |
| | 1 | 319 | | command.Parameters.AddWithValue("@limit", batchSize); |
| | 1 | 320 | | if (afterCreatedAtUtc is not null) |
| | | 321 | | { |
| | 1 | 322 | | var cursorParameter = command.Parameters.Add("@after_created_at", SqlDbType.DateTime2); |
| | 1 | 323 | | cursorParameter.Scale = 7; |
| | 1 | 324 | | cursorParameter.Value = afterCreatedAtUtc.Value.UtcDateTime; |
| | 1 | 325 | | command.Parameters.AddWithValue("@after_id", afterId ?? throw new ArgumentNullException(nameof(afterId))); |
| | | 326 | | } |
| | | 327 | | |
| | 1 | 328 | | var messages = new List<SqlServerChannelMessage>(batchSize); |
| | 1 | 329 | | await using var reader = await command.ExecuteReaderAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 330 | | while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false)) |
| | 1 | 331 | | messages.Add(new SqlServerChannelMessage( |
| | 1 | 332 | | reader.GetGuid(0), |
| | 1 | 333 | | reader.GetString(1), |
| | 1 | 334 | | reader.GetString(2), |
| | 1 | 335 | | new DateTimeOffset(reader.GetDateTime(3), TimeSpan.Zero), |
| | 1 | 336 | | reader.IsDBNull(4) ? null : new DateTimeOffset(reader.GetDateTime(4), TimeSpan.Zero))); |
| | 1 | 337 | | return messages; |
| | 1 | 338 | | } |
| | | 339 | | |
| | | 340 | | /// <summary> |
| | | 341 | | /// Atomically claims a message for live delivery: sets <c>acked_at</c> unless the publisher has |
| | | 342 | | /// already routed it to the lost-subscriber path (<c>recovery_claimed</c>). Returns <c>false</c> |
| | | 343 | | /// when recovery owns the message, so a slow-but-live waiter does not deliver a response the |
| | | 344 | | /// recovery callback already handled. Multiple processes may each win this claim, preserving |
| | | 345 | | /// cross-process fan-out, because it gates only on <c>recovery_claimed</c>, not on <c>acked_at</c>. |
| | | 346 | | /// </summary> |
| | | 347 | | public async Task<bool> TryClaimForDeliveryAsync(Guid messageId, CancellationToken cancellationToken) |
| | | 348 | | { |
| | 3 | 349 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 3 | 350 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 351 | | await using var command = connection.CreateCommand(); |
| | 1 | 352 | | command.CommandText = |
| | 1 | 353 | | $""" |
| | 1 | 354 | | UPDATE {MessageTable} |
| | 1 | 355 | | SET acked_at = COALESCE(acked_at, SYSUTCDATETIME()) |
| | 1 | 356 | | OUTPUT inserted.id |
| | 1 | 357 | | WHERE id = @id AND recovery_claimed = 0 AND expires_at > SYSUTCDATETIME(); |
| | 1 | 358 | | """; |
| | 1 | 359 | | command.Parameters.AddWithValue("@id", messageId); |
| | 1 | 360 | | var result = await command.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 361 | | return result is not null and not DBNull; |
| | 1 | 362 | | } |
| | | 363 | | |
| | | 364 | | /// <summary> |
| | | 365 | | /// Atomically claims a message for the lost-subscriber path: sets <c>recovery_claimed</c> only |
| | | 366 | | /// while no waiter has delivered (<c>acked_at IS NULL</c>). Returns <c>true</c> when recovery wins; |
| | | 367 | | /// <c>false</c> means a live waiter already took the message, so the publisher must not also fire |
| | | 368 | | /// the recovery callback. Row-level locking serializes this against <see cref="TryClaimForDeliveryAsync"/>. |
| | | 369 | | /// </summary> |
| | | 370 | | public async Task<bool> TryClaimForRecoveryAsync(Guid messageId, CancellationToken cancellationToken) |
| | | 371 | | { |
| | 1 | 372 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 373 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 374 | | await using var command = connection.CreateCommand(); |
| | 1 | 375 | | command.CommandText = |
| | 1 | 376 | | $""" |
| | 1 | 377 | | UPDATE {MessageTable} |
| | 1 | 378 | | SET recovery_claimed = 1 |
| | 1 | 379 | | OUTPUT inserted.id |
| | 1 | 380 | | WHERE id = @id AND acked_at IS NULL; |
| | 1 | 381 | | """; |
| | 1 | 382 | | command.Parameters.AddWithValue("@id", messageId); |
| | 1 | 383 | | var result = await command.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 384 | | return result is not null and not DBNull; |
| | 1 | 385 | | } |
| | | 386 | | |
| | | 387 | | /// <summary>Returns the database server's current UTC time, used as a clock-safe delivery watermark.</summary> |
| | | 388 | | public async Task<DateTimeOffset> GetServerTimeUtcAsync(CancellationToken cancellationToken) |
| | | 389 | | { |
| | 3 | 390 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 3 | 391 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 392 | | await using var command = connection.CreateCommand(); |
| | 1 | 393 | | command.CommandText = "SELECT SYSUTCDATETIME();"; |
| | 1 | 394 | | var result = await command.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 395 | | return result switch |
| | 1 | 396 | | { |
| | 1 | 397 | | DateTimeOffset dto => dto.ToUniversalTime(), |
| | 1 | 398 | | DateTime dt => new DateTimeOffset(DateTime.SpecifyKind(dt, DateTimeKind.Utc), TimeSpan.Zero), |
| | 1 | 399 | | _ => DateTimeOffset.UtcNow |
| | 1 | 400 | | }; |
| | 1 | 401 | | } |
| | | 402 | | |
| | | 403 | | public async Task<bool> IsMessageAcknowledgedAsync(Guid messageId, CancellationToken cancellationToken) |
| | | 404 | | { |
| | 3 | 405 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 3 | 406 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 407 | | await using var command = connection.CreateCommand(); |
| | 1 | 408 | | command.CommandText = |
| | 1 | 409 | | $""" |
| | 1 | 410 | | SELECT CAST(CASE WHEN acked_at IS NOT NULL THEN 1 ELSE 0 END AS bit) |
| | 1 | 411 | | FROM {MessageTable} |
| | 1 | 412 | | WHERE id = @id AND expires_at > SYSUTCDATETIME(); |
| | 1 | 413 | | """; |
| | 1 | 414 | | command.Parameters.AddWithValue("@id", messageId); |
| | 1 | 415 | | var result = await command.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 416 | | return result is bool acknowledged && acknowledged; |
| | 1 | 417 | | } |
| | | 418 | | |
| | | 419 | | public async Task UpsertSubscriberAsync(string correlationId, Guid registrationId, string instanceId, TimeSpan ttl, |
| | | 420 | | { |
| | 1 | 421 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 422 | | if (ShouldPrune(ref _lastSubscriberPruneTicks)) |
| | 1 | 423 | | await PruneExpiredSubscribersAsync(correlationId, cancellationToken).ConfigureAwait(false); |
| | | 424 | | |
| | 1 | 425 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 426 | | await using var command = connection.CreateCommand(); |
| | 1 | 427 | | command.CommandText = |
| | 1 | 428 | | $""" |
| | 1 | 429 | | MERGE {SubscriberTable} WITH (HOLDLOCK) AS target |
| | 1 | 430 | | USING (SELECT @correlation_id AS correlation_id, @registration_id AS registration_id) AS source |
| | 1 | 431 | | ON target.correlation_id = source.correlation_id AND target.registration_id = source.registration_id |
| | 1 | 432 | | WHEN MATCHED THEN |
| | 1 | 433 | | UPDATE SET instance_id = @instance_id, |
| | 1 | 434 | | expires_at = {AddMilliseconds("@ttl_ms")} |
| | 1 | 435 | | WHEN NOT MATCHED THEN |
| | 1 | 436 | | INSERT (correlation_id, registration_id, instance_id, expires_at) |
| | 1 | 437 | | VALUES (@correlation_id, @registration_id, @instance_id, {AddMilliseconds("@ttl_ms")}); |
| | 1 | 438 | | """; |
| | 1 | 439 | | command.Parameters.AddWithValue("@correlation_id", correlationId); |
| | 1 | 440 | | command.Parameters.AddWithValue("@registration_id", registrationId); |
| | 1 | 441 | | command.Parameters.AddWithValue("@instance_id", instanceId); |
| | 1 | 442 | | command.Parameters.AddWithValue("@ttl_ms", (long)ttl.TotalMilliseconds); |
| | 1 | 443 | | await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 444 | | } |
| | | 445 | | |
| | | 446 | | public async Task HeartbeatSubscribersAsync( |
| | | 447 | | string instanceId, |
| | | 448 | | IReadOnlyList<(string CorrelationId, Guid RegistrationId)> registrations, |
| | | 449 | | TimeSpan ttl, |
| | | 450 | | CancellationToken cancellationToken) |
| | | 451 | | { |
| | 3 | 452 | | if (registrations.Count == 0) |
| | 3 | 453 | | return; |
| | | 454 | | |
| | 3 | 455 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 3 | 456 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | | 457 | | |
| | | 458 | | // Two parameters per row plus instance/ttl stays under SQL Server's 2100-parameter cap. |
| | | 459 | | const int batchSize = 1000; |
| | 1 | 460 | | for (var offset = 0; offset < registrations.Count; offset += batchSize) |
| | | 461 | | { |
| | 1 | 462 | | var count = Math.Min(batchSize, registrations.Count - offset); |
| | 1 | 463 | | await using var command = connection.CreateCommand(); |
| | 1 | 464 | | var sourceRows = new string[count]; |
| | 1 | 465 | | for (var index = 0; index < count; index++) |
| | | 466 | | { |
| | 1 | 467 | | var (correlationId, registrationId) = registrations[offset + index]; |
| | 1 | 468 | | sourceRows[index] = $"(@correlation_id_{index}, @registration_id_{index})"; |
| | 1 | 469 | | command.Parameters.AddWithValue($"@correlation_id_{index}", correlationId); |
| | 1 | 470 | | command.Parameters.AddWithValue($"@registration_id_{index}", registrationId); |
| | | 471 | | } |
| | | 472 | | |
| | | 473 | | // MERGE upsert rather than a bare UPDATE, in the same WITH (HOLDLOCK) style as |
| | | 474 | | // UpsertSubscriberAsync: the caller only heartbeats registrations that are live in this |
| | | 475 | | // process, so a missing row means the pruner deleted it (e.g. after a >timeout stall) |
| | | 476 | | // — re-creating it here is what brings the waiter back from "permanently invisible". |
| | 1 | 477 | | command.CommandText = |
| | 1 | 478 | | $""" |
| | 1 | 479 | | MERGE {SubscriberTable} WITH (HOLDLOCK) AS target |
| | 1 | 480 | | USING (VALUES {string.Join(", ", sourceRows)}) AS source (correlation_id, registration_id) |
| | 1 | 481 | | ON target.correlation_id = source.correlation_id AND target.registration_id = source.registration_id |
| | 1 | 482 | | WHEN MATCHED THEN |
| | 1 | 483 | | UPDATE SET instance_id = @instance_id, |
| | 1 | 484 | | expires_at = {AddMilliseconds("@ttl_ms")} |
| | 1 | 485 | | WHEN NOT MATCHED THEN |
| | 1 | 486 | | INSERT (correlation_id, registration_id, instance_id, expires_at) |
| | 1 | 487 | | VALUES (source.correlation_id, source.registration_id, @instance_id, {AddMilliseconds("@ttl_ms")}); |
| | 1 | 488 | | """; |
| | 1 | 489 | | command.Parameters.AddWithValue("@instance_id", instanceId); |
| | 1 | 490 | | command.Parameters.AddWithValue("@ttl_ms", (long)ttl.TotalMilliseconds); |
| | 1 | 491 | | await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 492 | | } |
| | 3 | 493 | | } |
| | | 494 | | |
| | | 495 | | public async Task DeleteSubscriberAsync(string correlationId, Guid registrationId, CancellationToken cancellationTok |
| | | 496 | | { |
| | 3 | 497 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 3 | 498 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 499 | | await using var command = connection.CreateCommand(); |
| | 1 | 500 | | command.CommandText = $"DELETE FROM {SubscriberTable} WHERE correlation_id = @correlation_id AND registration_id |
| | 1 | 501 | | command.Parameters.AddWithValue("@correlation_id", correlationId); |
| | 1 | 502 | | command.Parameters.AddWithValue("@registration_id", registrationId); |
| | 1 | 503 | | await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 504 | | } |
| | | 505 | | |
| | | 506 | | public async Task<long> CountActiveSubscribersAsync(string correlationId, CancellationToken cancellationToken) |
| | | 507 | | { |
| | 3 | 508 | | await EnsureCreatedAsync(cancellationToken).ConfigureAwait(false); |
| | 3 | 509 | | if (ShouldPrune(ref _lastSubscriberPruneTicks)) |
| | 3 | 510 | | await PruneExpiredSubscribersAsync(correlationId, cancellationToken).ConfigureAwait(false); |
| | | 511 | | |
| | 3 | 512 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 513 | | await using var command = connection.CreateCommand(); |
| | 1 | 514 | | command.CommandText = |
| | 1 | 515 | | $""" |
| | 1 | 516 | | SELECT COUNT_BIG(*) |
| | 1 | 517 | | FROM {SubscriberTable} |
| | 1 | 518 | | WHERE correlation_id = @correlation_id AND expires_at > SYSUTCDATETIME(); |
| | 1 | 519 | | """; |
| | 1 | 520 | | command.Parameters.AddWithValue("@correlation_id", correlationId); |
| | 1 | 521 | | var result = await command.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 522 | | return result is long count ? count : 0L; |
| | 1 | 523 | | } |
| | | 524 | | |
| | | 525 | | private async Task PruneExpiredRecoveryAsync(string? correlationId, CancellationToken cancellationToken) |
| | | 526 | | { |
| | 3 | 527 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 528 | | await using var command = connection.CreateCommand(); |
| | 1 | 529 | | command.CommandText = correlationId is null |
| | 1 | 530 | | ? $"DELETE FROM {RecoveryTable} WHERE expires_at <= SYSUTCDATETIME();" |
| | 1 | 531 | | : $"DELETE FROM {RecoveryTable} WHERE correlation_id = @correlation_id AND expires_at <= SYSUTCDATETIME();"; |
| | 1 | 532 | | if (correlationId is not null) |
| | 1 | 533 | | command.Parameters.AddWithValue("@correlation_id", correlationId); |
| | 1 | 534 | | await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 535 | | } |
| | | 536 | | |
| | | 537 | | private async Task PruneExpiredMessagesAsync(CancellationToken cancellationToken) |
| | | 538 | | { |
| | 3 | 539 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 540 | | await using var command = connection.CreateCommand(); |
| | 1 | 541 | | command.CommandText = $"DELETE FROM {MessageTable} WHERE expires_at <= SYSUTCDATETIME();"; |
| | 1 | 542 | | await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 543 | | } |
| | | 544 | | |
| | | 545 | | private async Task PruneExpiredSubscribersAsync(string? correlationId, CancellationToken cancellationToken) |
| | | 546 | | { |
| | 3 | 547 | | await using var connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 548 | | await using var command = connection.CreateCommand(); |
| | 1 | 549 | | command.CommandText = correlationId is null |
| | 1 | 550 | | ? $"DELETE FROM {SubscriberTable} WHERE expires_at <= SYSUTCDATETIME();" |
| | 1 | 551 | | : $"DELETE FROM {SubscriberTable} WHERE correlation_id = @correlation_id AND expires_at <= SYSUTCDATETIME(); |
| | 1 | 552 | | if (correlationId is not null) |
| | 1 | 553 | | command.Parameters.AddWithValue("@correlation_id", correlationId); |
| | 1 | 554 | | await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 555 | | } |
| | | 556 | | |
| | | 557 | | private async Task<SqlConnection> OpenConnectionAsync(CancellationToken cancellationToken) |
| | | 558 | | { |
| | 3 | 559 | | var connection = new SqlConnection(_connectionString); |
| | | 560 | | try |
| | | 561 | | { |
| | 3 | 562 | | await connection.OpenAsync(cancellationToken).ConfigureAwait(false); |
| | 1 | 563 | | return connection; |
| | | 564 | | } |
| | 3 | 565 | | catch |
| | | 566 | | { |
| | 3 | 567 | | await connection.DisposeAsync().ConfigureAwait(false); |
| | 3 | 568 | | throw; |
| | | 569 | | } |
| | 1 | 570 | | } |
| | | 571 | | |
| | | 572 | | public static void ValidateIdentifier(string? value, string name) |
| | | 573 | | { |
| | 3 | 574 | | if (string.IsNullOrWhiteSpace(value)) |
| | 3 | 575 | | throw new InvalidOperationException($"{nameof(SqlServerAsyncResponseChannelOptions)}.{name} must be configur |
| | 3 | 576 | | if (!IsIdentifier(value)) |
| | 3 | 577 | | throw new InvalidOperationException( |
| | 3 | 578 | | $"{nameof(SqlServerAsyncResponseChannelOptions)}.{name} '{value}' must be a simple SQL Server identifier |
| | 3 | 579 | | } |
| | | 580 | | |
| | | 581 | | private static bool IsIdentifier(string value) |
| | | 582 | | { |
| | 3 | 583 | | if (value.Length == 0 || !(char.IsAsciiLetter(value[0]) || value[0] == '_')) |
| | 3 | 584 | | return false; |
| | | 585 | | |
| | 3 | 586 | | foreach (var c in value) |
| | | 587 | | { |
| | 3 | 588 | | if (!(char.IsAsciiLetterOrDigit(c) || c == '_')) |
| | 3 | 589 | | return false; |
| | | 590 | | } |
| | | 591 | | |
| | 3 | 592 | | return true; |
| | | 593 | | } |
| | | 594 | | |
| | 3 | 595 | | private static string Quote(string identifier) => "[" + identifier + "]"; |
| | | 596 | | |
| | | 597 | | private static string IndexName(string table, string suffix) |
| | | 598 | | { |
| | 3 | 599 | | var name = $"{table}_{suffix}_idx"; |
| | 3 | 600 | | return name.Length <= 128 ? name : name[..128]; |
| | | 601 | | } |
| | | 602 | | |
| | | 603 | | /// <summary> |
| | | 604 | | /// SQL expression adding a millisecond bigint parameter to the database clock. DATEADD only takes |
| | | 605 | | /// int arguments, so the value is split into whole seconds and a sub-second remainder — TTLs and |
| | | 606 | | /// retentions stay on the database clock, immune to app-side clock skew, without overflowing on |
| | | 607 | | /// long spans such as the 7-day recovery expiry. |
| | | 608 | | /// </summary> |
| | | 609 | | internal static string AddMilliseconds(string parameterName) |
| | 3 | 610 | | => $"DATEADD(SECOND, CAST({parameterName} / 1000 AS int), DATEADD(MILLISECOND, CAST({parameterName} % 1000 AS in |
| | | 611 | | |
| | | 612 | | internal static bool IsTransient(Exception exception) |
| | 3 | 613 | | => exception is not OperationCanceledException |
| | 3 | 614 | | && (exception is SqlException sqlException && SqlServerTransientFaults.IsTransient(sqlException) |
| | 3 | 615 | | || exception is TimeoutException); |
| | | 616 | | |
| | | 617 | | /// <summary> |
| | | 618 | | /// Stable application-lock resource for serializing schema creation. It must be deterministic |
| | | 619 | | /// across processes and identical to the transport store's resource for the same schema so both |
| | | 620 | | /// serialize their shared CREATE SCHEMA. |
| | | 621 | | /// </summary> |
| | | 622 | | internal static string SchemaLockResource(string schemaName) |
| | 3 | 623 | | => $"asyncresponse:ddl:{schemaName}"; |
| | | 624 | | |
| | | 625 | | /// <summary> |
| | | 626 | | /// Time-gates opportunistic pruning so the housekeeping DELETE runs at most once per |
| | | 627 | | /// <see cref="SqlServerAsyncResponseChannelOptions.PruneInterval"/> instead of on every operation. |
| | | 628 | | /// Read queries already filter on <c>expires_at</c>, so throttling pruning never affects correctness. |
| | | 629 | | /// </summary> |
| | | 630 | | private bool ShouldPrune(ref long lastTicks) |
| | | 631 | | { |
| | 3 | 632 | | var interval = _options.PruneInterval; |
| | 3 | 633 | | if (interval <= TimeSpan.Zero) |
| | 3 | 634 | | return true; |
| | | 635 | | |
| | 3 | 636 | | var now = DateTime.UtcNow.Ticks; |
| | 3 | 637 | | var last = Interlocked.Read(ref lastTicks); |
| | 3 | 638 | | return now - last >= interval.Ticks |
| | 3 | 639 | | && Interlocked.CompareExchange(ref lastTicks, now, last) == last; |
| | | 640 | | } |
| | | 641 | | } |
| | | 642 | | |
| | | 643 | | /// <summary> |
| | | 644 | | /// Classifies SQL Server errors worth retrying. <see cref="SqlException"/> exposes no public |
| | | 645 | | /// transient flag, so this mirrors the error numbers Microsoft's own retry guidance and the |
| | | 646 | | /// SqlClient configurable-retry defaults treat as transient, plus severity ≥ 20 (broken connection). |
| | | 647 | | /// </summary> |
| | | 648 | | internal static class SqlServerTransientFaults |
| | | 649 | | { |
| | | 650 | | private static readonly HashSet<int> TransientErrorNumbers = |
| | | 651 | | [ |
| | | 652 | | -2, // client-side command timeout |
| | | 653 | | 20, // instance does not support encryption |
| | | 654 | | 64, // connection lost during login |
| | | 655 | | 121, // transport semaphore timeout |
| | | 656 | | 233, // no process on the other end of the pipe |
| | | 657 | | 997, // overlapped I/O in progress |
| | | 658 | | 1204, // lock resources exhausted |
| | | 659 | | 1205, // deadlock victim |
| | | 660 | | 1222, // lock request timeout |
| | | 661 | | 4060, // database unavailable |
| | | 662 | | 4221, // readable secondary timeout |
| | | 663 | | 10053, // transport-level connection abort |
| | | 664 | | 10054, // transport-level connection reset |
| | | 665 | | 10060, // network unreachable / connect timeout |
| | | 666 | | 10928, // Azure SQL resource limit reached |
| | | 667 | | 10929, // Azure SQL minimum guarantee exceeded |
| | | 668 | | 40143, // Azure SQL connection failure |
| | | 669 | | 40197, // Azure SQL service processing error |
| | | 670 | | 40501, // Azure SQL service busy |
| | | 671 | | 40540, // Azure SQL service unavailable |
| | | 672 | | 40613, // Azure SQL database unavailable |
| | | 673 | | 49918, // cannot process request, not enough resources |
| | | 674 | | 49919, // cannot process create/update request |
| | | 675 | | 49920 // cannot process request, too many operations |
| | | 676 | | ]; |
| | | 677 | | |
| | | 678 | | public static bool IsTransient(SqlException exception) |
| | | 679 | | { |
| | | 680 | | if (exception.Class >= 20) |
| | | 681 | | return true; |
| | | 682 | | |
| | | 683 | | foreach (SqlError error in exception.Errors) |
| | | 684 | | { |
| | | 685 | | if (TransientErrorNumbers.Contains(error.Number)) |
| | | 686 | | return true; |
| | | 687 | | } |
| | | 688 | | |
| | | 689 | | return TransientErrorNumbers.Contains(exception.Number); |
| | | 690 | | } |
| | | 691 | | } |