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

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

Closed
rainersigwald opened this issue Jan 7, 2022 · 0 comments · Fixed by #7230
Closed

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

rainersigwald opened this issue Jan 7, 2022 · 0 comments · Fixed by #7230
Assignees
Labels
bug Task: GenerateResource Problems with the task itself, resgen.exe, and resx resources in general. triaged
Milestone

Comments

@rainersigwald
Copy link
Member

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.

@rainersigwald rainersigwald self-assigned this Jan 7, 2022
@rainersigwald rainersigwald added bug Task: GenerateResource Problems with the task itself, resgen.exe, and resx resources in general. labels Jan 7, 2022
@rainersigwald rainersigwald added this to the VS 17.1 milestone Jan 7, 2022
rainersigwald added a commit to rainersigwald/msbuild that referenced this issue Jan 7, 2022
Fixes dotnet#7229 by ensuring that MSBuild's processing of a `.txt` resource holds only the minimal lock: open for read and allowing other processes to read while it's open.
@rainersigwald rainersigwald modified the milestones: VS 17.1, VS 17.2 Jan 7, 2022
Forgind pushed a commit that referenced this issue Jan 7, 2022
Fixes #7229 by ensuring that MSBuild's processing of a `.txt` resource holds only the minimal lock: open for read and allowing other processes to read while it's open.
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Task: GenerateResource Problems with the task itself, resgen.exe, and resx resources in general. triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants