Discussion:
Exception thrown on reconnect
(too old to reply)
o***@musiker.nu
2007-04-23 09:12:31 UTC
Permalink
I have a problem with a client/server remoting application that I have
created. When the client is shut down and restarted within a few
seconds, the following exception is thrown when the server calls the
client trying to update it:

The write operation failed, see inner exception.

Server stack trace:
at System.Net.Security.NegotiateStream.ProcessWrite(Byte[] buffer,
Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.Write(Byte[] buffer, Int32
offset, Int32 count)
at
System.Runtime.Remoting.Channels.ChunkedMemoryStream.WriteTo(Stream
stream)
at
System.Runtime.Remoting.Channels.Tcp.TcpClientSocketHandler.GetRequestStream(IMessage
msg, Int32 contentLength, ITransportHeaders headers)
at
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage
msg, ITransportHeaders requestHeaders, Stream requestStream)
at
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage
msg, ITransportHeaders requestHeaders, Stream requestStream,
ITransportHeaders& responseHeaders, Stream& responseStream)
at
System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage
msg)

Exception rethrown at [0]:
at Server.Server.UpdateClient()

If the client is restarted after 30 seconds, the problem won't appear.
If the client is shut down and restarted twice within a few seconds
the problem only appears the first time. Does this give anyone a clue
to what may cause this problem? Can this be related to some channel/
port issue? I use TcpChannel and a fix port number.
unknown
2010-03-11 09:24:24 UTC
Permalink
The TCP client transport sink contains a socket cache with a default timeout of 10 seconds. If the server tries to reconnect to the same host and port within that interval, the old socket will be re-used. If the client was restarted, then the connection will have been closed on the other end and the transport layer will throw.

You can force the transport sink to create a new socket each time by setting the socketCacheTimeout value on the TCP channel to 0. Here is some sample code:

BinaryClientFormatterSinkProvider clientFormatterSinkProvider = new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider serverFormatterSinkProvider = new BinaryServerFormatterSinkProvider();

serverFormatterSinkProvider.TypeFilterLevel = TypeFilterLevel.Full;

Hashtable dictionary = new Hashtable();

dictionary.Add("port", port);
dictionary.Add("typeFilterLevel", TypeFilterLevel.Full);
dictionary.Add("name", Guid.NewGuid().ToString());
dictionary.Add("socketCacheTimeout", 0);
dictionary.Add("socketCachePolicy", SocketCachePolicy.AbsoluteTimeout);

IChannel channel = new TcpChannel(dictionary, clientFormatterSinkProvider, serverFormatterSinkProvider);

ChannelServices.RegisterChannel(channel, true);




oska wrote:

Exception thrown on reconnect
23-Apr-07

I have a problem with a client/server remoting application that I hav
created. When the client is shut down and restarted within a fe
seconds, the following exception is thrown when the server calls th
client trying to update it

The write operation failed, see inner exception

Server stack trace
at System.Net.Security.NegotiateStream.ProcessWrite(Byte[] buffer
Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest
at System.Net.Security.NegotiateStream.Write(Byte[] buffer, Int3
offset, Int32 count
a
System.Runtime.Remoting.Channels.ChunkedMemoryStream.WriteTo(Strea
stream
a
System.Runtime.Remoting.Channels.Tcp.TcpClientSocketHandler.GetRequestStream(IMessag
msg, Int32 contentLength, ITransportHeaders headers
a
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessag
msg, ITransportHeaders requestHeaders, Stream requestStream
a
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessag
msg, ITransportHeaders requestHeaders, Stream requestStream
ITransportHeaders& responseHeaders, Stream& responseStream
a
System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessag
msg

Exception rethrown at [0]
at Server.Server.UpdateClient(

If the client is restarted after 30 seconds, the problem won't appear
If the client is shut down and restarted twice within a few second
the problem only appears the first time. Does this give anyone a clu
to what may cause this problem? Can this be related to some channel
port issue? I use TcpChannel and a fix port number.

Previous Posts In This Thread:

On Monday, April 23, 2007 5:12 AM
oska wrote:

Exception thrown on reconnect
I have a problem with a client/server remoting application that I hav
created. When the client is shut down and restarted within a fe
seconds, the following exception is thrown when the server calls th
client trying to update it

The write operation failed, see inner exception

Server stack trace
at System.Net.Security.NegotiateStream.ProcessWrite(Byte[] buffer
Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest
at System.Net.Security.NegotiateStream.Write(Byte[] buffer, Int3
offset, Int32 count
a
System.Runtime.Remoting.Channels.ChunkedMemoryStream.WriteTo(Strea
stream
a
System.Runtime.Remoting.Channels.Tcp.TcpClientSocketHandler.GetRequestStream(IMessag
msg, Int32 contentLength, ITransportHeaders headers
a
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessag
msg, ITransportHeaders requestHeaders, Stream requestStream
a
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessag
msg, ITransportHeaders requestHeaders, Stream requestStream
ITransportHeaders& responseHeaders, Stream& responseStream)
at
System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage
msg)

Exception rethrown at [0]:
at Server.Server.UpdateClient()

If the client is restarted after 30 seconds, the problem won't appear.
If the client is shut down and restarted twice within a few seconds
the problem only appears the first time. Does this give anyone a clue
to what may cause this problem? Can this be related to some channel/
port issue? I use TcpChannel and a fix port number.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Sending SMTP email from within BizTalk Orchestration
http://www.eggheadcafe.com/tutorials/aspnet/9dd0f346-baf9-4674-a50f-1716445b26bc/sending-smtp-email-from-w.aspx
Jamal Samedov
2010-04-02 13:14:12 UTC
Permalink
Hi Cassius,
what is wrong with this behavior?
Trying to send something through dead socket should raise an exception.
Catch the exception, destroy socket and continue listen to incomming
connections.

J.N. Samedov,
Post by unknown
The TCP client transport sink contains a socket cache with a default
timeout of 10 seconds. If the server tries to reconnect to the same host
and port within that interval, the old socket will be re-used. If the
client was restarted, then the connection will have been closed on the
other end and the transport layer will throw.
You can force the transport sink to create a new socket each time by
setting the socketCacheTimeout value on the TCP channel to 0. Here is
BinaryClientFormatterSinkProvider clientFormatterSinkProvider = new
BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider serverFormatterSinkProvider = new
BinaryServerFormatterSinkProvider();
serverFormatterSinkProvider.TypeFilterLevel = TypeFilterLevel.Full;
Hashtable dictionary = new Hashtable();
dictionary.Add("port", port);
dictionary.Add("typeFilterLevel", TypeFilterLevel.Full);
dictionary.Add("name", Guid.NewGuid().ToString());
dictionary.Add("socketCacheTimeout", 0);
dictionary.Add("socketCachePolicy", SocketCachePolicy.AbsoluteTimeout);
IChannel channel = new TcpChannel(dictionary, clientFormatterSinkProvider,
serverFormatterSinkProvider);
ChannelServices.RegisterChannel(channel, true);
Exception thrown on reconnect
23-Apr-07
I have a problem with a client/server remoting application that I have
created. When the client is shut down and restarted within a few
seconds, the following exception is thrown when the server calls the
The write operation failed, see inner exception.
at System.Net.Security.NegotiateStream.ProcessWrite(Byte[] buffer,
Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.Write(Byte[] buffer, Int32
offset, Int32 count)
at
System.Runtime.Remoting.Channels.ChunkedMemoryStream.WriteTo(Stream
stream)
at
System.Runtime.Remoting.Channels.Tcp.TcpClientSocketHandler.GetRequestStream(IMessage
msg, Int32 contentLength, ITransportHeaders headers)
at
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage
msg, ITransportHeaders requestHeaders, Stream requestStream)
at
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage
msg, ITransportHeaders requestHeaders, Stream requestStream,
ITransportHeaders& responseHeaders, Stream& responseStream)
at
System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage
msg)
at Server.Server.UpdateClient()
If the client is restarted after 30 seconds, the problem won't appear.
If the client is shut down and restarted twice within a few seconds
the problem only appears the first time. Does this give anyone a clue
to what may cause this problem? Can this be related to some channel/
port issue? I use TcpChannel and a fix port number.
On Monday, April 23, 2007 5:12 AM
Exception thrown on reconnect
I have a problem with a client/server remoting application that I have
created. When the client is shut down and restarted within a few
seconds, the following exception is thrown when the server calls the
The write operation failed, see inner exception.
at System.Net.Security.NegotiateStream.ProcessWrite(Byte[] buffer,
Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.Write(Byte[] buffer, Int32
offset, Int32 count)
at
System.Runtime.Remoting.Channels.ChunkedMemoryStream.WriteTo(Stream
stream)
at
System.Runtime.Remoting.Channels.Tcp.TcpClientSocketHandler.GetRequestStream(IMessage
msg, Int32 contentLength, ITransportHeaders headers)
at
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage
msg, ITransportHeaders requestHeaders, Stream requestStream)
at
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage
msg, ITransportHeaders requestHeaders, Stream requestStream,
ITransportHeaders& responseHeaders, Stream& responseStream)
at
System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage
msg)
at Server.Server.UpdateClient()
If the client is restarted after 30 seconds, the problem won't appear.
If the client is shut down and restarted twice within a few seconds
the problem only appears the first time. Does this give anyone a clue
to what may cause this problem? Can this be related to some channel/
port issue? I use TcpChannel and a fix port number.
Submitted via EggHeadCafe - Software Developer Portal of Choice
Sending SMTP email from within BizTalk Orchestration
http://www.eggheadcafe.com/tutorials/aspnet/9dd0f346-baf9-4674-a50f-1716445b26bc/sending-smtp-email-from-w.aspx
a***@lemoen.com
2010-04-15 14:30:21 UTC
Permalink
What's wrong with it is that an undocumented internal implementation
detail - the socket pool - is producing behaviour inconsistent with
the semantics of the interface.

If I make a request for a connection to a good IP endpoint, the timing
of my request should not impact whether or not I get back a usable
socket or some dead piece of junk.

At the very least the interface should express the implementation's
behaviour by, say, adding a parameter which allows you to indicate
whether you are prepared to accept a cached socket.

Loading...