Event Id 1040 on Exchange Servers
We might notice this error in the Event Viewer on Exchange Servers for the source MsExchangeActiveSync
https://exchangequery.files.wordpress.com/2016/10/untitled2.png?w=715&h=82
Event Type: Warning
Event Source: MSExchange ActiveSync
**Event Category: Requests **
Event ID: 1040
Date: 3/10/2016
Time: 12:54:22 PM
The average of the most recent [513] heartbeat intervals used by clients is less than or equal to [540].
Make sure that your firewall configuration is set to work correctly with Exchange ActiveSync and Direct Push technology. Specifically, make sure that your firewall is configured so that requests to Exchange ActiveSync do not expire before they have the opportunity to be processed.
This warning is not an issue on Exchange Servers. This is a mismatch value configured on the Network Load Balancer which serves the Client is not configured correctly.
Active Sync Uses Direct push technology to retrieve the emails from the server. In order to initiate a direct push communication between the ActiveSync Client and the Exchange Server it uses the heart beat interval values.
In order for the Direct Push Technology to work it involves two processes, one request from the ActiveSync Mobile (Client) and the response from the Exchange Server. When the Client notifies any changes on the user's mailbox the changes are transmitted over persistent HTTP or HTTPS connection through direct push.
Below is the process of ActiveSync Request to the server:
1) The Client issues an HTTP request to Exchange Server asking for any changes occurred in the user mailbox in the specified time. Basically it queries inbox, contacts, calendar, etc.
2) After Exchange receives this request it looks for the specific mailbox and sees the changes in the folders until the specified time limit expires. After the time-out period exceeds it issues an HTTP 200 OK response to the clients. It then gives a response request to the client with all the updates about the folders.
3) The Client then receives the response from Exchange and can be any of the below:
HTTP 200 OK – No Change on Folders. If this is the case the client will reissue the ping request on the next heartbeatinterval value.
HTTP 200 OK – Change in folders – Will get the updates on each folder that was changed. After the sync is done it will reissue the request in next interval.
NO Response – It lowers the time interval in the ping request and then re-issues the request again in the minimum heartbeatinterval value to get the update.
So basically these HearBeatInterval values should match between the values set on Network Load Balancers and the Exchange Servers.
Let's have a look at the values of HearBeatInterval on Exchange Servers.
Where are these values stored in Exchange 2016?
These values can be seen in the web.config file in the below location in the installation directory
C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\Sync
There are four values as below
https://exchangequery.files.wordpress.com/2016/10/untitled1.png?w=600
MinHeartBeatInterval – The minimum number of seconds that the client waits between issuing heartbeat commands to the server.The default value in Exchange 2016 is 60 seconds. If this value is too small the client will send the HTTP request very often and will consume the power of the device.
**MaxHeartBeatInterval –**The maximum number of seconds that a client waits between issuing heartbeat commands.The Default value is 59 Minutes on Exchange 2016 Server.
**HeartBeatSampleSize - **This is a bucket where the server collects all the recent heartbeat intervals that the server received from the Active Sync Clients. It keeps this value to see how the clients are sending the activesync HTTP request to the server and ensures they are matching with the specified values. The default value is it waits for 200 heart beat intervals.
**HeartBeatAlertThreshold - **If the collected HBsamplesize value is more than or not meeting the configured value heartbeat maximum or minimum value in this specified time interval then it logs an event in the application log. The default value configured is 9 minutes.
Lets say if the HTTP(S) connections time-out value is not configured as longer than 59 minutes on the firewall and if its value is lesser than the value on Exchange Servers, once a ActiveSync HTTP request is timed out on the F/W, ActiveSync Mobile client will send another HTTP request which may cause connection overload. In order to avoid this the Exchange server will trigger an alert and mark an event in the event log.
A short living time-out value will initiate new HTTP requests from the mobile device more frequently. This will also drain the battery of the device very quickly considering more HTTP requests are initiated from the device.
The best practice is to increase the firewall Time Out Values for HTTP requests to Exchange Servers Active Sync Virtual Directory to give a better experience to the users. The time-out value on the firewall can be equal to or greater than the values specified on the Exchange 2016 servers.