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

Exception running InspectCode and then directly after TeamCity.ImportData #805

Closed
laurentkempe opened this issue Apr 4, 2016 · 16 comments
Closed
Labels
Milestone

Comments

@laurentkempe
Copy link

Here is the exception

[17:00:11][Step 1/1] Importing data from 'artifacts/_ReSharperReports/inspectcode-report.xml' (45.71 KB) with 'ReSharperInspectCode' processor
[17:00:11][Step 1/1] Caught exception while running service process importData
[17:00:11]
[Step 1/1] java.io.FileNotFoundException: C:\Temp\buildAgent1\work\ab9b99833ae569b1\artifacts_ReSharperReports\inspectcode-report.xml (The process cannot access the file because it is being used by another process)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.(FileInputStream.java:138)
at jetbrains.buildServer.dotnetTools.agent.inspectCode.InspectCodeFileProcessor.processReport(InspectCodeFileProcessor.java:54)
at jetbrains.buildServer.dotnetTools.agent.inspectCode.InspectCodeDataProcessor.processData(InspectCodeDataProcessor.java:38)
at jetbrains.buildServer.agent.impl.inspections.DataImportServiceMessage$1.run(DataImportServiceMessage.java:93)
at jetbrains.buildServer.agent.impl.serviceProcess.impl.ThreadedServiceProcessFactory$1.run(ThreadedServiceProcessFactory.java:31)
at java.lang.Thread.run(Thread.java:745)

This is due to this line which does resultsFile.Open(FileMode.Open)

Looks like there is the same problem here https://github.com/cake-build/cake/blob/develop/src/Cake.Common/Tools/DupFinder/DupFinderRunner.cs#L193 cc @gep13

@devlead
Copy link
Member

devlead commented Apr 4, 2016

Yeah that stream should be wrapped in a using statement so it's disposed directly.

@gep13
Copy link
Member

gep13 commented Apr 4, 2016

Or, should the FileAccess be changed to FileAccess.Read, so it doesn't lock the file?

@gep13
Copy link
Member

gep13 commented Apr 4, 2016

i.e.

var xmlDoc = XDocument.Load(resultsFile.OpenRead());

@gep13
Copy link
Member

gep13 commented Apr 4, 2016

or it could even be ReadLines() which handles the disposing for us, assuming we know what the Encoding is.

@devlead
Copy link
Member

devlead commented Apr 4, 2016

Well it could be read, but important part probably the dispose part, on phone now, but should be something like.

XDocument xmlDoc;
using(var stream = resultsFile.OpenRead())
{
    xmlDoc = XDocument.Load(stream);
}

@laurentkempe
Copy link
Author

I would go with the using!

@devlead
Copy link
Member

devlead commented Apr 4, 2016

Perhaps xml load alias so it can be reused 😉

@lionelplessis
Copy link

Why not simply XDocument.Load(filePath);?

@patriksvensson
Copy link
Member

@lionelplessis Not possible to write unit tests for that path so stream is preferred.

@lionelplessis
Copy link

Thanks @patriksvensson, I had the feeling I was missing something but still I had to ask just in case 😃. Makes sense.

gep13 added a commit to gep13/cake that referenced this issue Apr 4, 2016
- Rather than opening the File, thus locking it, use a Stream to dispose
of the lock on the file when working with it has completed.
devlead added a commit that referenced this issue Apr 4, 2016
(GH-805) Correcting issue with locked file
gep13 added a commit that referenced this issue Apr 7, 2016
- Rather than opening the File, thus locking it, use a Stream to dispose
of the lock on the file when working with it has completed.
@gep13 gep13 added this to the v0.10.1 milestone Apr 7, 2016
@gep13 gep13 added the Bug label Apr 7, 2016
@gep13 gep13 closed this as completed Apr 7, 2016
@gep13
Copy link
Member

gep13 commented Apr 7, 2016

@laurentkempe @lionelplessis can you please give the 0.10.1 version of Cake a run, and confirm that the issue that you raised has been resolved? Thanks!

@laurentkempe
Copy link
Author

@gep13 I will and let you know asap. Currently I am rebuilding our whole build infrastructure. But that should be done till tonight

@gep13
Copy link
Member

gep13 commented Apr 7, 2016

@laurentkempe perfect, thank you!

@laurentkempe
Copy link
Author

selfie-0

👍 Works perfectly! well done @gep13

@gep13
Copy link
Member

gep13 commented Apr 7, 2016

@laurentkempe glad to hear it! Please let us know if you run into any other issues, or if you have further questions!

@laurentkempe
Copy link
Author

@gep13 don't worry I will do so 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants