-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix files kept in use in XslTransformation #6946
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks fine overall, with some nits. I tested deleting the file in the unit test without your change and the task indeed holds onto the file.
@@ -386,7 +393,7 @@ public void OutputTest() | |||
/// Setting correct "Parameter" parameters for Xsl. | |||
/// </summary> | |||
[Fact] | |||
public void XsltParamatersCorrect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the change is here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in "parameters"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry about that, I'm on the verge of OCD for these kind of things, and when I spotted that while skimming through the tests, I couldn't resist...
if (xmlInputs[xmi].Key == XslTransformation.XmlInput.XmlModes.XmlFile) | ||
{ | ||
string xmlInputPath = ((TaskItem[])xmlInputs[xmi].Value)[0].ItemSpec; | ||
File.Delete(xmlInputPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File.Delete(xmlInputPath); | |
File.Delete(xmlInputPath); | |
File.Exists(xmlInputPath).ShouldBeFalse(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this would be a separate test so we explicitly know xsltransform shouldn't be holding on to a file. Can we move this to its own test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will push shortly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, this showed that the xsl was also kept locked (I'm pretty sure this was the case before, sure it should rarely be an issue in real life, but still...)
7e23cbc
to
f62f7f0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the contribution!
This fixes a potential regression that made it to 17.0, but I'm not sure how realistic it is someone could run into this. @lanfeust69 how did you discover this bug? |
Because it broke our build, of course 😄 ! Our specific use-case is post-processing |
f62f7f0
to
5b67e83
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably point to main instead of vs17.1, but I think it's otherwise ready to go.
5b67e83
to
9ad0936
Compare
Following dotnet#6863, the created XmlReader is no longer responsible for its underlying stream. This can cause the build process to hold on to the processed file, preventing its removal. This can especially be a problem when the transformation is in fact aimed at the input file itself, where we want to create the transformed file, then move it to the original.
9ad0936
to
8cd6f36
Compare
The PR that caused this regression made it to 17.0 so I pointed to vs17.0. We should get this approved, merge it, and let it propagate up. cc @dotnet/kitten |
Thanks for the contribution @lanfeust69! |
Fixes #6962
Work item (Internal use): https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1417029
Summary
The XslTransformation now holds a lock on its input xml file.
Customer Impact
Customers that expect to modify/use the input files to the
XslTransformation
task are unable to due to a lock on the file.Regression?
Yes, in VS 17.0 P5+
Testing
Added regression test & customer verified the fix.
Risk
Low: makes use of a parameter that was previously passed null. This parameter now tells the xmlreader to drop its lock on the file as soon as it's done.
Original Post
Following #6863, the created
XmlReader
is no longer responsible for itsunderlying stream. This can cause the build process to hold on to the
processed file, preventing its removal. This can especially be a problem
when the transformation is in fact aimed at the input file itself, where
we want to create the transformed file, then move it to the original.