nunit-console-x86 crashes with socketexception

Bug #881958 reported by Theo Harper
26
This bug affects 4 people
Affects Status Importance Assigned to Milestone
NUnit V2
Fix Released
High
Charlie Poole

Bug Description

We run our unit tests under a Jenkins build server, via nant.

To run the tests we use the nunit-console as our code is compiled as .NET 4.

<exec program="${nunit-console.exe}"
      workingdir="${CCNetArtifactDirectory}"
      commandline="${shortFileName} /xml:${resultFileName} /nologo /nodots /nothread /domain=Single /framework:net-4.0"/>

We are using NUnit 2.5.10.

However, intermittently we see this exception, which stops our builds:

Unhandled Exception:
     [exec] System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
     [exec]
     [exec] Server stack trace:
     [exec] at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
     [exec] at System.Runtime.Remoting.Channels.SocketStream.Read(Byte[] buffer, Int32 offset, Int32 size)
     [exec] at System.Runtime.Remoting.Channels.SocketHandler.ReadFromSocket(Byte[] buffer, Int32 offset, Int32 count)
     [exec] at System.Runtime.Remoting.Channels.SocketHandler.Read(Byte[] buffer, Int32 offset, Int32 count)
     [exec] at System.Runtime.Remoting.Channels.Tcp.TcpFixedLengthReadingStream.Read(Byte[] buffer, Int32 offset, Int32 count)
     [exec] at System.IO.BinaryReader.ReadBytes(Int32 count)
     [exec] at System.Runtime.Serialization.Formatters.Binary.SerializationHeaderRecord.Read(__BinaryParser input)
     [exec] at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadSerializationHeaderRecord()
     [exec] at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
     [exec] at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
     [exec] at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
     [exec] at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryResponseMessage(Stream inputStream, IMethodCallMessage reqMsg, Boolean bStrictBinding)
     [exec] at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.DeserializeMessage(IMethodCallMessage mcm, ITransportHeaders headers, Stream stream)
     [exec] at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)
     [exec]
     [exec] Exception rethrown at [0]:
     [exec] at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
     [exec] at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
     [exec] at NUnit.Core.TestAgent.Stop()
     [exec] at NUnit.Util.ProcessRunner.Dispose()
     [exec] at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)
     [exec] at NUnit.ConsoleRunner.Runner.Main(String[] args)

Tags: console

Related branches

Revision history for this message
Paul Jensen (p-jensen) wrote :

I am running into the exact same problem for our unit tests under the NUnit runner on a Bamboo build server. The log shows the exact same error as above.

I was also using local Bamboo variables for the directory path to the DLL to test. The occurances of this error went down considerably when I explicitly indicated the path to the DLL, however the variables are still in there (as they are defined at the Project level and I'm using them for other Plans/Jobs), and the log does show them as environmental variable substitutions when calling NUnit (not that I necessarily think this is the cause, just pointing out similarities).

Revision history for this message
tony partheniou (tonyp-c) wrote :

I'm also having the same issue with Nunit 2.5.10 and nunit-console-x86.

The strange this is that the exception occurred after the unit test passed.

  <message>Tests run: 1, Errors: 0, Failures: 0, Inconclusive: 0, Time: 20.6235966 seconds</message>
  <message> Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0</message>
  <message>Unhandled Exception:</message>
  <message>System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host</message>
  <message>Server stack trace: </message>
  <message> at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)</message>
  <message> at System.Runtime.Remoting.Channels.SocketStream.Read(Byte[] buffer, Int32 offset, Int32 size)</message>
  <message> at System.Runtime.Remoting.Channels.SocketHandler.ReadFromSocket(Byte[] buffer, Int32 offset, Int32 count)</message>
  <message> at System.Runtime.Remoting.Channels.SocketHandler.Read(Byte[] buffer, Int32 offset, Int32 count)</message>
  <message> at System.Runtime.Remoting.Channels.Tcp.TcpFixedLengthReadingStream.Read(Byte[] buffer, Int32 offset, Int32 count)</message>
  <message> at System.IO.BinaryReader.ReadBytes(Int32 count)</message>
  <message> at System.Runtime.Serialization.Formatters.Binary.SerializationHeaderRecord.Read(__BinaryParser input)</message>
  <message> at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadSerializationHeaderRecord()</message>
  <message> at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()</message>
  <message> at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)</message>
  <message> at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)</message>
  <message> at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryResponseMessage(Stream inputStream, IMethodCallMessage reqMsg, Boolean bStrictBinding)</message>
  <message> at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.DeserializeMessage(IMethodCallMessage mcm, ITransportHeaders headers, Stream stream)</message>
  <message> at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)</message>
  <message>Exception rethrown at [0]: </message>
  <message> at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)</message>
  <message> at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)</message>
  <message> at NUnit.Core.TestAgent.Stop()</message>
  <message> at NUnit.Util.ProcessRunner.Dispose()</message>
  <message> at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)</message>
  <message> at NUnit.ConsoleRunner.Runner.Main(String[] args)</message>

Revision history for this message
Paul Jensen (p-jensen) wrote :

I believe what was causing my issue was not using the right framework with NUnit. I was able to fix the issue by passing in a value for the /framework parameter such as: /framework=v4.0.30319

Hope this helps.

Revision history for this message
tony partheniou (tonyp-c) wrote :

Thanks ! I will give it a try

tags: added: console
Changed in nunitv2:
status: New → Triaged
importance: Undecided → High
assignee: nobody → Charlie Poole (charlie.poole)
milestone: none → 2.6.0
status: Triaged → Fix Committed
Revision history for this message
Charlie Poole (charlie.poole) wrote :

Suppressed the exception when calling RemoteTestAgent.Stop(), in case the agent process has already exited.

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.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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