I have a server written in C that closes the connection if the connection is sitting idle for a specific time. I have an issue (that rarely happens). Read is failing on the client side and it says Connection broken. I suspect the server is closing the connection and the client is sending some data at the same time.
Consider the following scenario (A is server, B is the client)
B initiates the connection and the connection between A and B is established.
B is sitting idle and the idle timeout is reached.
A initiates the close
Before B receives the FIN from A, it starts sending request to A
After B sends the request, it will read the response
Since A has already closed the connection, B is not able to read.
My questions are
Is this a possible situation ?
How to handle idle timeout for clients?
How to close the connection between A and B properly (avoid B sending request during the process). In short, how to close the connection atomically?
By my only little more than rudimentary network experience... and assuming that you are talking about a connection-oriented connection like TCP/IP in contrary to UDP/IP that is connection-less.
Yes, of course. You cannot avoid it.
There are multiple ways to do it, but all of them include: Send something from the client before the server's timeout elapses. If the client has no data to send, let it send something like a "life sign". This could be an empty data message, it all depends on your application protocol. Or make the timeout as long as necessary, including some margin. Some protocol timeout only after 3 times of allowed idle time.
You cannot close the connection atomically, because client and server are separated. Each packet on the network needs some time to be transmitted, and both can start sending at the very same moment, the server its closing message, and the client a new data message. There is nothing that you can do about this.
You need to make the client handle this situation properly. For example, it can accept such a broken connection and interpret it as closed. You should have already some reaction, if the server closes the connection while the client is idle.
How to close the connection between A and B properly (avoid B sending request during the process).
Server detects timeout
Server sends timeout detection message to the Client
Server waits for a reply (if timeout, assume Client dead)
if Client receives a timeout detection from the Server, it replies with ACK (or something like that)
if Server receives an ACK from the Client, then 'gracefully' closes the connection
from now on, neither the Server nor the Client should send/receive any messages (after sending the ACK, do not immediately close the connection from the client side, do linger for the agreed timeout - see setsockopt: SO_LINGER)
On top of that, like the other answers suggested, the Client should send a heartbeat if idle (to avoid timeout detections).
I have a procedure which identifies number of employees and send email to them dynamically (add names in TO / from).
Out of 5000 emails triggered only 700-800 gets sent other are in re-trying or failed status every time.
getting below error :
The mail could not be sent to the recipients because of the mail server failure.
(Sending Mail using Account 1 (2017-04-14T12:40:47).
Exception Message: Cannot send mails to mail server. (The operation has timed out.).
)
The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2017-04-13T16:43:32). Exception Message: Cannot send mails to mail server. (Service not available, closing transmission channel.The server response was: 4.3.2 The maximum number of concurrent connections has exceeded a limit, closing transmission channel).
Isn't if the server did not receive any messages from the client within the (1.5) * KeepAlivetime and the client did not send any PINGREQ within the aforementioned period, the server should DISCONNECT?
If yes, why I am receiving LWT message which is should not be received as DISCONNECT occures?
Last will and Testement will be sent if the client does not explicitly disconnect it's self.
If the broker disconnects the client due to a ping time out then the LWT will be sent, this is the specific reason why the LWT feature exists.
Or do you mean your now disconnected client is receiving it's own LWT?
I have a simple ZMQ 3.2 publisher which sends out messages and there are N number of subscribers that connect and disconnect to this publisher.
Is there any way in which the publisher can have details(IP, Name, Type... etc) of the subscriber that connects to it?
I am researching SQL Server 2008 Service Broker. I want to get data from a web service and insert it into a queue. I understand sending messages from one queue to another, but how do I get the data into the first queue, in the first place?
When you SEND a message, its goes directly to transmission queue and from transmission queue to target services queue.
If you want to keep message for the lifetime of conversation, then you can ALTER QUEUE and use RETENTION = ON. In this case, message will be deleted from sender queue, when conversation ends.