ServiceStack ProtoBuf Error: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host - servicestack

I have a ServiceStack service on a server and I am trying to run a program that connects to that service. I am getting the intermittent error below. This is the stack trace and anything that was below this was just the point in my program at which I was calling the server. The most frustrating part is that it is not consistent. If it fails and I restart the program it may fail but at a different point, it may not fail at all. (It usually does fail again, but after a different amount of time). Almost always it is the same call to the server I am making but I have seen it happen during other calls as well. Any help would be greatly appreciated as this has been an issue I have been trying to solve for a while now.
System.AggregateException: One or more errors occurred. ---> System.Runtime.Serialization.SerializationException:
ProtoBufServiceClient:
Error deserializing: Unable to read data from the transport connection:
An existing connection was forcibly closed by the remote host. --->
System.IO.IOException: Unable to read data from the transport connection:
An existing connection was forcibly closed by the remote host. --->
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at ProtoBuf.ProtoReader.Ensure(Int32 count, Boolean strict)
at ProtoBuf.ProtoReader.TryReadUInt32VariantWithoutMoving(Boolean trimNegative, UInt32& value)
at ProtoBuf.ProtoReader.TryReadUInt32Variant(UInt32& value)
at ProtoBuf.ProtoReader.ReadFieldHeader()
at proto_32(Object , ProtoReader )
at ProtoBuf.ProtoReader.ReadTypedObject(Object value, Int32 key, ProtoReader reader, Type type)
at proto_64(Object , ProtoReader )
at ProtoBuf.ProtoReader.ReadTypedObject(Object value, Int32 key, ProtoReader reader, Type type)
at proto_84(Object , ProtoReader )
at ProtoBuf.ProtoReader.ReadTypedObject(Object value, Int32 key, ProtoReader reader, Type type)
at proto_56(Object , ProtoReader )
at ProtoBuf.ProtoReader.ReadTypedObject(Object value, Int32 key, ProtoReader reader, Type type)
at proto_50(Object , ProtoReader )
at ProtoBuf.ProtoReader.ReadTypedObject(Object value, Int32 key, ProtoReader reader, Type type)
at proto_78(Object , ProtoReader )
at ProtoBuf.Meta.TypeModel.DeserializeCore(ProtoReader reader, Type type, Object value, Boolean noAutoCreate)
at ProtoBuf.Meta.TypeModel.Deserialize(Stream source, Object value, Type type, SerializationContext context)
at ProtoBuf.Serializer.Deserialize[T](Stream source)
at ServiceStack.ProtoBuf.ProtoBufServiceClient.DeserializeFromStream[T](Stream stream)
--- End of inner exception stack trace ---
at ServiceStack.ProtoBuf.ProtoBufServiceClient.DeserializeFromStream[T](Stream stream)
at ServiceStack.ServiceClientBase.GetResponse[TResponse](WebResponse webResponse)
at ServiceStack.ServiceClientBase.Send[TResponse](String httpMethod, String relativeOrAbsoluteUrl, Object request)

Related

How to mark the redis instance typing with `decode_responses=False` param in python3

I used to mark it as client:Redis[bytes] = Redis(decode_responses=False),
but it throw the error raise TypeError(f"{cls} is not a generic class")
what's the correct typing of bytes Redis.

Is it possible to pass a connection string to StrictRedis in python?

I am unable to find an answer to this while googling, but it seems like it should be something that is doable. I am retrieving a Redis connection string from my password manager. I would like to take this connection string and pass it to Redis. All the examples I have seen are in the following format.
redis.StrictRedis(host=myHostname, port=6380, password=myPassword, ssl=True)
I have also tried doing the following.
r = redis.StrictRedis()
r.ConnectionString = myConnectionString
That results in an error
ConnectionRefusedError: [Errno 111] Connection refused
Is there a way to simply pass this connection string? Seems counterproductive for me to have to retrieve it and then split it up.
My connection string looks like this after it has been retrieved.
xxx.redis.cache.yyy.net:6380,password=redacted,ssl=True,abortConnect=False
You don't have a connection string that the Python Redis client supports; that's a .NET StackExchange.Redis configuration string. You'll have to parse out the components yourself, skipping the abortConnection option:
hostport, *options = myConnectionString.split(",")
host, _, port = hostport.partition(":")
arguments = {}
for option in options:
opt, _, value = option.partition("=")
if opt == "port":
value = int(value)
elif opt == "ssl":
value = value.lower() == "true"
elif opt == "abortConnect":
continue
arguments[opt] = value
client = redis.Redis(host, port=int(port), **arguments)
Note that the above is a very simple parser based on the options you currently use. If more StackExchange.Redis configuration features need to be supported, you'll have to write more code to map those to equivalent Python Redis features (if available).
For supported connection string URLs you can use the redis.from_url() function, or the Redis.from_url() class method
Returns an active Redis client generated from the given database URL.
Note the supported schemes:
Three URL schemes are supported:
redis:// <http://www.iana.org/assignments/uri-schemes/prov/redis>_ creates a normal TCP socket connection
rediss:// <http://www.iana.org/assignments/uri-schemes/prov/rediss>_ creates a SSL wrapped TCP socket connection
unix:// creates a Unix Domain Socket connection
Note that StrictRedis is just an alias for the redis.client.Redis class.

protobuf: string content is overlapped when 2 different instance of the same message in multithread

Recently I encountered a protobuf problem that the string was overlapped. The scenario is :
1/ defined a message like in proto file.
message fund_inout_rsp {
uint64 seq_no = 1;
uint32 err_id = 2;
string err_msg = 3
};
and then convert this message to C++ code using protoc --cpp_out。
so I got a class named fund_inout_rsp.
2/ Now there are two thread A and B.
In thread A,
fund_inout_rsp instance1;
instance1.set_err_msg(u8("123456789"))
instance1.SerializeToArray();
send out by TCP
In thread B,
fund_inout_rsp instance2;
instance2.set_err_msg(u8("abcd"));
instance2.SerializeToArray();
send out by TCP
3/ the TCP receiver got a message.
"abcd56789"
it seems that the instance1's err_msg is overlapped by instance2's err_msg.
The following is the auto generated code by protoc.
fund_inout_rsp::set_err_msg(const char* value) {
err_msg_.SetNoArena(
&google::protobuf::internal::GetEmptyStringAlreadyInited(),
std::string(value))
}
Can anyone give me a hint how to solve this problem?
Thanks in advance.

Encoding Not supported Execption while parsing HL7 message

I have a C#.NET application in which i am trying to construct an HL7 message and then send to other Application using NHAPI .The message is successfully constructed but it when i am trying to extract throws an error :Encoding NotsupportedException
Specifications:
.NET framework- 4
HL7 version-2.5
Language:C#
here is the piece of code
PipeParser ParserADT = new PipeParser();
IMessage ParsedADTmsg = ParserADT.Parse(ADTMsg);
string Msgstr = ParsedADTmsg.GetStructureName();
I get the exception immediately after the line above.
The constructed message:
MSH|^~\&|HIS|HIS1|||201405291223||ADT^A01^ADT_A01|73944|P|2.5
EVN||201405291223
PID|||102||Oberoi^Anjali^^^Ms||20140529|Female|||||^^PH|^^CP
NK1|1234||||||||||||||||||||||||||||||^^CP
PV1||Emergency –
Replace the space before EVN, NK1, and PV1 with a new line character, so that your message looks like this:
MSH|^~\&|HIS|HIS1|||201405291223||ADT^A01^ADT_A01|73944|P|2.5
EVN||201405291223 PID|||102||Oberoi^Anjali^^^Ms||20140529|Female|||||^^PH|^^CP
NK1|1234||||||||||||||||||||||||||||||^^CP
PV1||Emergency

Uploading sharepoint document exception using SaveBinaryDirect

I have a Windows Application that saves .pdfs to a SharePoint Document Library. It works fine except this one file. Whenever I use SaveBinaryDirect with this 10.1MB file I get the following exception:
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.File.SaveBinary(ClientContext context, String serverRelativeUrl, Stream stream, String etag, Boolean overwriteIfExists, SaveBinaryCheckMode checkMode)
at Microsoft.SharePoint.Client.File.SaveBinaryDirect(ClientContext context, String serverRelativeUrl, Stream stream, Boolean overwriteIfExists)
at BKWatch.BKWatchViewModel.UploadDocument(String siteURL, String documentListName, String documentListURL, String documentName, Byte[] documentStream, Int64 AccountId, String DebtorName, Nullable`1 Pages, String Title)
I have already tried the following:
clientContext.PendingRequest.RequestExecutor.WebRequest.KeepAlive = false;
System.Net.ServicePointManager.MaxServicePointIdleTime = 600000;
clientContext.RequestTimeout = 600000;
Increasing max size in SharePoint - already at 50 MB
Increasing max size in IIS web.config - Already at 2GB
Thanks.
Well after a couple long phone conversations with Microsoft, they think there is a bug in the SaveBinaryDirect code and recommended I use the ClientObject.Add functionality instead. Seems to be working so far.
I have encountered this problem with Microsoft.SharePoint.Client.File.SaveBinaryDirect when uploading a number of big files in a row.
The fix for this, is on each time you are using SaveBinaryDirect, wrap it with a try-catch, and catch System.Net.WebException.
once Webexception is caught, run the same SaveBinaryDirect command you ran before, and it should work.

Resources