Skip to content

Race condition on text resources processed in multiple project instances #7229

@rainersigwald

Description

@rainersigwald

We have periodically seen this failure in our own build:

src\Tasks\system.design\system.design.txt(0,0): error MSB3103: Invalid Resx file. The process cannot access the file 'D:\a\1\s\src\Tasks\system.design\system.design.txt' because it is being used by another process.

Today I looked into it. I suspect this flow of things:

private void ReadTextResources(ReaderInfo reader, String fileName)
{
// Check for byte order marks in the beginning of the input file, but
// default to UTF-8.
using (LineNumberStreamReader sr = new LineNumberStreamReader(fileName, new UTF8Encoding(true), true))

internal LineNumberStreamReader(String fileName, Encoding encoding, bool detectEncoding)
: base(File.Open(fileName, FileMode.Open, FileAccess.Read), encoding, detectEncoding)

File.Open does not specify FileShare.Read, which defaults to "no sharing". So if this is run on the same file in parallel (for instance, in our Tasks project which is multitargeted), there's a possibility that the second attempt to read the file fails because the first one is still holding a lock.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions