Tests fail with IOException: Too many open files

Bug #993247 reported by Eberhard Beilharz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit V2
Fix Released
High
Eberhard Beilharz

Bug Description

When I run the unit tests of our project on Linux they fail with an IOException: Too many open files. The tests work fine on Windows, and they work if I run them fixture by fixture, or if I run them in the GUI.

Related branches

Revision history for this message
Eberhard Beilharz (ermshiperete) wrote :

It turns out that AssemblyReader opens a dll and closes it in AssemblyReader.Dispose. However, AssemblyResolver that creates AssemblyReader never disposes it, so the files stays open until eventually GC calls Dispose. On Linux this causes us to eventually run out of file handles.

Attached is a suggested fix. I did not include a unit test because I don't know how I could test this specific scenario.

Revision history for this message
Jv (jv-ravichandran) wrote : Re: [Bug 993247] [NEW] Tests fail with IOException: Too many open files

in Linux it seems lots of files are opened/used by a process. here is a
link:

http://www.cyberciti.biz/tips/linux-procfs-file-descriptors.html

maybe finding out the number of open file descriptors and how many
irrelevant to your tests might help more. just my two pence. pls do let me
know if this suggestion is irrelevant...

regards,

jv

On Wed, May 2, 2012 at 6:32 PM, Eberhard Beilharz <<email address hidden>
> wrote:

> Public bug reported:
>
> When I run the unit tests of our project on Linux they fail with an
> IOException: Too many open files. The tests work fine on Windows, and
> they work if I run them fixture by fixture, or if I run them in the GUI.
>
> ** Affects: nunitv2
> Importance: Undecided
> Status: New
>
> --
> You received this bug notification because you are a member of NUnit
> Developers, which is subscribed to NUnit V2.
> https://bugs.launchpad.net/bugs/993247
>
> Title:
> Tests fail with IOException: Too many open files
>
> Status in NUnit V2 Test Framework:
> New
>
> Bug description:
> When I run the unit tests of our project on Linux they fail with an
> IOException: Too many open files. The tests work fine on Windows, and
> they work if I run them fixture by fixture, or if I run them in the
> GUI.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/nunitv2/+bug/993247/+subscriptions
>

--
Regards,

Ravichandran Jv
http://ravichandranjv.blogspot.com

Revision history for this message
Charlie Poole (charlie.poole) wrote :

The fix looks good to me. It could be tested using a mock, but I'm not sure we really need to do that.

Changed in nunitv2:
status: New → Triaged
importance: Undecided → High
assignee: nobody → Eberhard Beilharz (ermshiperete)
Revision history for this message
Jv (jv-ravichandran) wrote : Re: [Bug 993247] Re: Tests fail with IOException: Too many open files

this seems to be a well-known occurrence for oracle users on linux so maybe
linux users would know how to increase the max number of file descriptors
through the shell..just like increasing VM in windows. maybe clr should
provide for a command line switch to increase the max file descriptor.

jv

On Wed, May 2, 2012 at 6:48 PM, Eberhard Beilharz <<email address hidden>
> wrote:

> It turns out that AssemblyReader opens a dll and closes it in
> AssemblyReader.Dispose. However, AssemblyResolver that creates
> AssemblyReader never disposes it, so the files stays open until
> eventually GC calls Dispose. On Linux this causes us to eventually run
> out of file handles.
>
> Attached is a suggested fix. I did not include a unit test because I
> don't know how I could test this specific scenario.
>
> ** Patch added: "Suggested fix"
>
> https://bugs.launchpad.net/nunitv2/+bug/993247/+attachment/3125057/+files/Bug-993247-Fix-Too-many-open-files-problem-when-runn.patch
>
> --
> You received this bug notification because you are a member of NUnit
> Developers, which is subscribed to NUnit V2.
> https://bugs.launchpad.net/bugs/993247
>
> Title:
> Tests fail with IOException: Too many open files
>
> Status in NUnit V2 Test Framework:
> New
>
> Bug description:
> When I run the unit tests of our project on Linux they fail with an
> IOException: Too many open files. The tests work fine on Windows, and
> they work if I run them fixture by fixture, or if I run them in the
> GUI.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/nunitv2/+bug/993247/+subscriptions
>

--
Regards,

Ravichandran Jv
http://ravichandranjv.blogspot.com

Revision history for this message
Eberhard Beilharz (ermshiperete) wrote :

@Jv: I know how to increase the max number of file descriptors and how to find out the number of open files under Linux.

However, I think it's pretty bad if you have tests that open a file, do something and then close the file again and you get that "too many open files" exception. For me that smells pretty heavily. If I run a test and the test is implemented correctly the environment should be in the same state afterwards as it was before. Otherwise we might run into problems if we run a test in NUnit GUI multiple times - it will suddenly behave differently.

And while I know how to increase the max number of file descriptors, not everyone on my team knows that or needs to know - the tool should be implemented correctly.

Increasing the max number of file descriptors is a workaround but it can't be the solution - unless we really need > 1000 files open at a time.

Revision history for this message
Jv (jv-ravichandran) wrote : Re: [Bug 993247] Re: Tests fail with IOException: Too many open files

@Eberhard

no suggestion on the contrary from me that the using directive in your
suggested fix for your scenario must be the right one ...

another point that the using directive in your suggested fix must be the
right one is that file handles are usually considered as part of the
unmanaged world and so obviously the GC is going to be least concerned
about it and hence it should be the app's responsibility to dispose off
file handles after use.

jv

On Thu, May 3, 2012 at 12:19 AM, Eberhard Beilharz <
<email address hidden>> wrote:

> @Jv: I know how to increase the max number of file descriptors and how
> to find out the number of open files under Linux.
>
> However, I think it's pretty bad if you have tests that open a file, do
> something and then close the file again and you get that "too many open
> files" exception. For me that smells pretty heavily. If I run a test and
> the test is implemented correctly the environment should be in the same
> state afterwards as it was before. Otherwise we might run into problems
> if we run a test in NUnit GUI multiple times - it will suddenly behave
> differently.
>
> And while I know how to increase the max number of file descriptors, not
> everyone on my team knows that or needs to know - the tool should be
> implemented correctly.
>
> Increasing the max number of file descriptors is a workaround but it
> can't be the solution - unless we really need > 1000 files open at a
> time.
>
> --
> You received this bug notification because you are a member of NUnit
> Developers, which is subscribed to NUnit V2.
> https://bugs.launchpad.net/bugs/993247
>
> Title:
> Tests fail with IOException: Too many open files
>
> Status in NUnit V2 Test Framework:
> Triaged
>
> Bug description:
> When I run the unit tests of our project on Linux they fail with an
> IOException: Too many open files. The tests work fine on Windows, and
> they work if I run them fixture by fixture, or if I run them in the
> GUI.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/nunitv2/+bug/993247/+subscriptions
>

--
Regards,

Ravichandran Jv
http://ravichandranjv.blogspot.com

Changed in nunitv2:
milestone: none → 2.6.1
Revision history for this message
Charlie Poole (charlie.poole) wrote :

TestAssemblyBuilder needs the same fix.

Changed in nunitv2:
status: Triaged → Fix Committed
Changed in nunitv2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.