Skip to content
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

[ODS-6632] Handle deserialization failures gracefully for the Serialized Data feature - 7.3 patch #1223

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CodeQL Security Scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
working-directory: ./Ed-Fi-ODS/.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Lib edFi.admin.dataaccess.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
working-directory: ./.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Lib edFi.common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
working-directory: ./.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Lib edFi.loadtools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
working-directory: ./.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Lib edFi.ods.api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
working-directory: ./.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Lib edFi.ods.common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
working-directory: ./.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Lib edFi.ods.standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
working-directory: ./Ed-Fi-ODS/.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Lib edFi.security.dataaccess.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
working-directory: ./.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Pkg EdFi.Ods.CodeGen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
working-directory: ./Ed-Fi-ODS/.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
working-directory: ./Ed-Fi-ODS/.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
working-directory: ./Ed-Fi-ODS/.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Pkg EdFi.Ods.Minimal.Template.TPDM.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
working-directory: ./Ed-Fi-ODS/.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Pkg EdFi.Ods.Minimal.Template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
working-directory: ./Ed-Fi-ODS/.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
working-directory: ./Ed-Fi-ODS/.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
working-directory: ./Ed-Fi-ODS/.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
working-directory: ./Ed-Fi-ODS/.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Pkg EdFi.Ods.Populated.Template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
working-directory: ./Ed-Fi-ODS/.github/workflows
run: sudo ./install-mono.sh
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Setup MSBuild for .NET Framework 4.8
uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce #v2.0.0
- name: Cache Nuget packages
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 #v4.0.1
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 #v4.2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*', '**/configuration.packages.json') }}
Expand Down
30 changes: 30 additions & 0 deletions Application/EdFi.Ods.Common/Repositories/EntityDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using System;
using System.Threading;
using System.Threading.Tasks;
using EdFi.Ods.Common.Context;
using EdFi.Ods.Common.Infrastructure;
Expand All @@ -24,6 +26,10 @@ public class EntityDeserializer : IEntityDeserializer

private readonly ILog _logger = LogManager.GetLogger(typeof(EntityDeserializer));

private long _deserializationFailedCount;
private DateTime _lastDeserializationWarningTime;
private readonly TimeSpan _deserializationWarningPeriod = TimeSpan.FromMinutes(5);

public EntityDeserializer(
ISurrogateIdMutator[] surrogateIdMutators,
ISessionFactory sessionFactory,
Expand All @@ -48,6 +54,30 @@ public async Task<TEntity> DeserializeAsync<TEntity>(IItemRawData itemRawData)
// Deserialize the entity
entity = MessagePackHelper.DecompressAndDeserializeAggregate<TEntity>(itemRawData.AggregateData);
}
catch (Exception ex)
{
Interlocked.Increment(ref _deserializationFailedCount);

// Determine if "quiet" period for logging warnings has elapsed
if (DateTime.Now > (_lastDeserializationWarningTime + _deserializationWarningPeriod))
{
// Reset the tracking variables
_lastDeserializationWarningTime = DateTime.Now;
var failedCount = Interlocked.Exchange(ref _deserializationFailedCount, 0);

string messageCountAddendum = null;

if (failedCount > 1)
{
messageCountAddendum = $" and {failedCount - 1:N0} other item(s) since last warning";
}

// Prevent exceptions during deserialization from failing the processing -- revert to returning a null instance
_logger.Warn($"Unable to deserialize entity of type '{typeof(TEntity).Name}' (with AggregateId of {itemRawData.AggregateId}){messageCountAddendum}. Falling back to load through NHibernate repository. HINT: Serialized data is in an inconsistent state. Clear the values in the 'AggregateData' column for the affected records. Next warning won't occur until '{_lastDeserializationWarningTime.Add(_deserializationWarningPeriod)}'...", ex);
}

return default;
}
finally
{
// Indicate that deserialization is finished
Expand Down
Loading