Skip to content

An error occurred while reading the key ring #3370

@da1rren

Description

@da1rren

We are running some integration tests in a docker container and it appears that we are encountering the following exception. Everything is pretty standard we don't even directly reference the data protector and it all works outside the container.

.NET core 2.1

Exception

Microsoft (R) Test Execution Command Line Tool Version 15.7.0
Copyright (c) Microsoft Corporation.  All rights reserved.
Starting test execution, please wait...
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {d53a4cf9-f22c-4723-833b-1c9d3d92de1c} may be persisted to storage in unencrypted form.
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {c882fb25-423d-40b0-af65-175dc37bd26f} may be persisted to storage in unencrypted form.
Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider[48]
      An error occurred while reading the key ring.
System.IO.IOException: The process cannot access the file '/root/.aspnet/DataProtection-Keys/key-c882fb25-423d-40b0-af65-175dc37bd26f.xml' because it is being used by another process.
   at System.IO.FileStream.Init(FileMode mode, FileShare share)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.IO.File.OpenRead(String path)
   at Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository.ReadElementFromFile(String fullPath)
   at Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository.GetAllElementsCore()+MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository.GetAllElements()
   at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.GetAllKeys()
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.CreateCacheableKeyRingCore(DateTimeOffset now, IKey keyJustAdded)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.CreateCacheableKeyRingCore(DateTimeOffset now, IKey keyJustAdded)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.ICacheableKeyRingProvider.GetCacheableKeyRing(DateTimeOffset now)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow)

Dockerfile

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src

# Copy supporting projects
COPY Onboard.Api.sln ./
COPY docker-compose.dcproj ./
COPY Onboard.Core.Tests/Onboard.Core.Tests.csproj Onboard.Core.Tests/

# Copy Core
COPY Onboard.Core/Onboard.Core.csproj Onboard.Core/
COPY Onboard.Core/Nuget.config Onboard.Core/

# Copy main project
COPY Onboard.Api.People/Onboard.Api.People.csproj Onboard.Api.People/

# Copy test project
COPY Onboard.Api.People.Tests/Onboard.Api.People.Tests.csproj Onboard.Api.People.Tests/


# Restore packages
RUN dotnet restore Onboard.Core --configfile Onboard.Core/Nuget.config -nowarn:msb3202,nu1503
RUN dotnet restore Onboard.Core.Tests --configfile Onboard.Core/Nuget.config -nowarn:msb3202,nu1503
RUN dotnet restore Onboard.Api.People --configfile Onboard.Core/Nuget.config -nowarn:msb3202,nu1503
RUN dotnet restore Onboard.Api.People.Tests --configfile Onboard.Core/Nuget.config -nowarn:msb3202,nu1503

COPY . .

# Build project
WORKDIR /src/Onboard.Api.People.Tests
ENTRYPOINT ["dotnet", "test", "Onboard.Api.People.Tests.csproj", "-l", "trx;LogFileName=/artifacts/people-results.trx"]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions