Telling When Couchbase Query Times Out - c#

I am using couchbase using the .NET client to interact with it. I need to be able to differentiate the cause of a failed call to my couchbase box and log them accurately. I've tried provoking a timeout in my testing environment but I have been unable to.
Reading the .net client documentation it appears that ExecuteGet returns an IGetOperationResult object that contains both an exception property and a status code property. The status codes would appear to correspond to this table. I haven't found in the documentation for the .NET client as to whether or not it throws an exception like the Java client. Also, the status codes from the memcached table doesn't seem to have a clear status code value that corresponds to a timeout.
How would one tell whether or not the configured timeout has been exceeded from a call besides not having a value returned?

The StatusCode property is set only when a response from the server is sent. A timeout would result in no response from the server, therefore a null StatusCode. A connection timeout should result in the Exception value being populated on the GetOperationResult...
https://github.com/couchbase/couchbase-net-client/blob/2dc8a63208dfa8b991290d128b14002ad4c43f53/src/Enyim.Caching/Memcached/PooledSocket.cs#L68
However, it is quite possible that somewhere further up the Enyim stack, the original timeout exception is being swallowed and rewrapped in another exception. When you experience timeouts, are you seeing any value for the Exception property?

Related

Get a StreamSocket's Connection Status (UWP)

I'm using a StreamSocket in a Windows Universal app to make a TCP/IP connection to a text based game (the socket is left open for an extended period of time). I have it connecting and returning data fine. Most socket implementations I've used in the past have a property or function (or a way to poll the socket) and get the status (whether it's open, closed, broken, pending, etc.).
I haven't been able to find a way to do this with the StreamSocket.
My question is, How do I query the status of the StreamSocket connection to see if it's dropped (without waiting until I send something down the pipe for it to error out)?
E.g., something so I could do something like:
if (this.Socket.Status != Status.Connected)...
if (this.Socket.Status != Status.Connected)
The code you wrote was quite elegant , however, as far as I know there is no such api provided by uwp.
The Windows.Networking.Sockets namespace has convenient helper methods and enumerations for handling errors when using sockets and WebSockets. This can be useful for handling specific network exceptions differently in your app.
An error encountered on DatagramSocket, StreamSocket, or StreamSocketListener operation is returned as an HRESULT value. The SocketError.GetStatus method is used to convert a network error from a socket operation to a SocketErrorStatus enumeration value. Most of the SocketErrorStatus enumeration values correspond to an error returned by the native Windows sockets operation. An app can filter on specific SocketErrorStatus enumeration values to modify app behavior depending on the cause of the exception.
For parameter validation errors, an app can also use the HRESULT from the exception to learn more detailed information on the error that caused the exception. Possible HRESULT values are listed in the Winerror.h header file. For most parameter validation errors, the HRESULT returned is E_INVALIDARG
.

What is the difference between a SmtpException and a SmtpFailedRecipientException

I have been looking at the MSDN documentation and I cannot seem to work out what the difference is:
SmtpException Class
Represents the exception that is thrown when the SmtpClient is not able to complete a Send or SendAsync operation.
SmtpFailedRecipientException
Represents the exception that is thrown when the SmtpClient is not able to complete a Send or SendAsync operation to a particular recipient.
I can't find any information in the documentation to what "operation to a particular recipient" actually means.
Aside
The reason I ask is because I am trying to catch certain exceptions in my client application and execute different methods accordingly.
For Example:
If server is down I would like to leave the file where it is
If send address is invalid I would like to move the file to "Failed" folder
The source for SmtpClient.cs indicates that SmtpException is used for exceptions trying to get to the point of sending the message. SmtpFailedRecipientException is for an error reaching the client (but everything on the server worked fine).

Websphere MQ isConnected variable after exception

I use an C# Console Application to put and read messages of the MQ..
When the application starts, it connect once with the MQ and then the connection should be always upholded.
The program runs every 30 sec and check if new messages are in the queue or a database(to put them on the queue) and check the isConnected-variable if its true.
But what happen if an exception(2009 - connection broke) in the Put/Get occur? Will the isConnected automatically set to false?
Is the connection automatically disconnected or do I have to call Disconnect() in the error handling?
Thanks!
To answer your exact question, for a basic .net application (non XMS) using MQQueue for put/get, if you get CERTAIN bad return codes from the underlying API call which indicates a connection issue, MQ will attempt an MQBACK and an MQDISC for you and will result in the connection handle being invalidated (IsConnected would return false) and an exception being thrown. However if an exception occurs outside those return codes then no attempt is made to do anything with the connection.
Basically you should not code an application relying on this behaviour, when the most simple answer is to always disconnect if you get an exception which relates to the quality of the connection or queue manager. For example, a no message available etc type exception doesnt mean you need to disconnect but a connection broken obviously does. There is no harm in calling disconnect on an already disconnected connection.

WCF timeout error with code running fine

I have a project that uses a WCF service to do some database queries, builds an "Environment" object (which consists of different database class objects) and returns it inside a "Workspace" object to the client. It's been running fine.
I added another "Database" type to the service with all the correct contract and method updates. Now when I call the method the client times out after 1 minute. In debugging it take about 3-5 seconds to hit the end of the service method. Then nothing happens for the rest of the minute until on the client side we see a timeout problem. There are no errors/exceptions thrown.
Please see below:
Calling from client:
490 m_ScanWorkspace = m_Connection.ScanProxy.CreateEnvironments
End of service method:
477 return tWorkspace;
478 }
It takes 3-5 seconds to get to line 478 in the service. F10 shows it's complete.
Nothing happens until 1 minute later when line 490 in the client shows a timeout error. while debugging I can see a valid object in tWorkspace.
Firstly, set up WCF tracing using the Diagnostics namespace. Just use the first example on that tutorial and WCF will dump out a log of all activity, which you can open up in the log viewer. It will tell you exactly where the call is failing, which will help you pinpoint the problem.
WCF is great, but the error messages it gives are cryptic and often close to useless. A timeout after 1 minute doesn't necessarily mean what a timeout would normally mean - i.e. couldn't find the server. It could be other issues.
More than likely there will be a threshold exceeded which causes the response object to be incomplete. This could be array length, string content length, message size, and so on. You will find some of these detailed here: https://stackoverflow.com/a/480191/146077
Good luck!

Websocket compatibility issues

I am using the plain C# await httpListenerContext.AcceptWebSocketAsync(subProtocol: null), everything seems to work great and data is being sent and transmitted from Chrome successfully, however sometimes the connection seems to get dropped for no reason or the client will send the data partially, this is especially annoying since the data is JSON and I will only get half the object (and I am certain I send it full on the client)
I am testing on localhost so any connection issues aren't a possibility (not that they would be anyway because of TCP)
I see that I sometimes receive the following exception:
Error while processing account:The 'System.Net.Web
Sockets.ServerWebSocket' instance cannot be used for communication because it ha
s been transitioned into the 'Aborted' state.:System.Net.WebSockets.WebSocketExc
eption (0x80004005): The 'System.Net.WebSockets.ServerWebSocket' instance cannot
be used for communication because it has been transitioned into the 'Aborted' s
tate. ---> System.OperationCanceledException: The operation was canceled.
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at System.Net.WebSockets.WebSocketHttpListenerDuplexStream.<ReadAsyncCore>d__

Categories