Biztalk 2006 SQL Adapter polling bug. Potentially you can bring Biztalk Server to halt within few minutes.

Posted at: 2/12/2007 at 6:47 AM by saravana

Scenario:

We send product catalogue to our partner on regular basis via SFTP. There are 3 different types of catalogue message FULL CATALOGUE, PRICE DELTA, and AVAILABILITY DELTA. Price Delta and Availability Delta messages are send every hour, whereas FULL CATALOGUE will be send only once in a month (message size is roughly around 10MB).

Architecture:

Architecture is quite straight forward we have configured a BizTalk "Receive Port" with 3 "Receive Locations" using SQL Adapter. The SQL Receive locations got different polling interval settings as shown below.

PRICE_DELTA: Polls every 1 hour.

AVAILABILITY_DELTA: Polls every 1 hour

FULL_CATALOGUE: Supposed to poll every 720 Hours once.

Through some filter conditions corresponding "Send Ports" will pick up the message and transfer it to our parter via SFTP.

So, where is the bug?

As soon as you enable the FULL CATALOGUE (with 720 Hours polling interval) SQL "Receive Location", you'll see hundreds of messages flooding into your BizTalk server via the SQL Receive Location. If you don't notice it straight away with in minutes you'll have 1000's of messages coming non-stop into BizTalk server and to Message Box, blocking all the network traffice, maximum memory utilization in the Biztalk Host machines and SQL Server.

In our case the effect was pretty bad. We did the configuration at end of business and left it over night. Next day morning, Our Biztalk Server disk space was full (because we temporarily write this particular file to local disk for logging purpose), Event viewer was full of Error Messages related to SQL, pretty much both the BizTalk and SQL machines were  useless.

We started analysing the problem and figured out SQL Adapter polling is working without any issue upto 596 hours, you put any value above 596, your SQL Adapter will start polling messages every 10millisecond or so non-stop clogging the whole Message Box.

Some dissection into Microsoft.Bizatalk.Adapter.SQL.dll

Out of curiosity I just went to figure out the root case for this bug. Lutz reflector came handy to do some dissection of the Microsoft.Bizatalk.Adapter.SQL.dll, which revealed the next polling interval is calculated by the method GetNextActivationTime() inside the TimeIntervalSchedule class, luckily the reflector is showed me the source code as well.

The problem here is "seconds" properties is of type integer (Int32) so the maximum value it can hold is 2147483647. The polling logic will be ok till 596 hours. (i.e 597 * 60 * 60 * 1000 = 2145600000 MilliSeconds), But if you try putting anything bigger than 596 is going to exceed the maxmimum threshold value for Int32 and the function is going to return a DateTime value in the past, which will result in constant polling by SQL Adapter non-stop thinking it has some work to do. Unfortunately in our case it ended up in one of the biggest messages in our system (10MB).

Reproduction of the BUG using windows application. 

You can easily reproduce this behaviour by writing this simple code.

private void button1_Click(object sender, EventArgs e)
{
int f = 597 * 60 * 60;
MessageBox.Show(GetNextActivationTime(f).ToString());
}
public DateTime GetNextActivationTime(int seconds)
{
//return (DateTime.Now + TimeSpan.FromMilliseconds((double)(0x3e8 * seconds)));
return (DateTime.Now + TimeSpan.FromMilliseconds((double)(1000 * seconds)));
}

When I tested this code on 08 Feb 2007, I got the following results

For 596 hours : 05/03/2007 08:47:23

For 597 hours:  14/01/2007 16:45:39 (which is in the past)

Changing the datatype from int to uint will produce the correct result.

So, what's the solution?

1. Option 1: Restrict the User Interface in SQL Adapter to certain values, in our case not more than 597 hours. There is bug in the UI as well, it just throws an exception saying you can enter value more than 65535 (max of uint) inspite of you choosing hours, minutes or seconds.

2. Option 2: SQL Adapter code need a fix.

Sample Application for Download

I'v just put a sample Biztalk Application you can use to see this behaviour. It got 1 Schema to support SQL Adapter, 1 SQL Receive port and 1 FILE send port to "C:\temp". The SQL Adapter will poll data from BtsMgmtDb, here is the query I've used

SELECT NAME, DATEMODIFIED FROM adm_HostInstance FOR XML AUTO

Default binding got the value of 596 hours, which is OK, change it to 597 and see how many messages you are getting on your C:\Temp folder.

Note: Disable the "Receive Location" to stop polling after a minute or so. Dont forget to disable the SQL Receive location after the experiment.

Nandri!

Saravana

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  Categories: BizTalk General
Actions: Email this article Email | Kick it! | DZone it! | Save to del.icio.us | Technorati Links
Post Information: Permanent LinkPermalink | CommentsComments(8) | Comments RSS

Comments

Tuesday, February 27, 2007 11:08 AM
Anonymous
Anonymous
Ya the concept is some what similar to my concept which i require.What i want is Actually I have one receive pipeline which picks new product data from one location and Availablity data in other location.Theory is after product data is entered in database the availabilty data can be viewed and inserted.When we place these files seperately one after other to their location for a time gap.then there is no problem.But when i drop simultaneously the product data is inserted and availablity data shows errors..Here what i require is : Can i schedule the pipeline for a short duration (time span -2 mins)so that it processes automatically.. Could u help me in this case..
Tuesday, March 06, 2007 11:36 AM
Ram
Ram
No response .... R u guys away for vacation ????
Wednesday, March 07, 2007 6:46 PM
Saravana Kumar
Hello there,
First of all I didn't try to explain any concept in this post, but explained a potential problem with SQL adapters polling mechanism duration calculation. Your question is not related to this post in anyway. Coming to your question, it's normally a bad practice to place delay logic to wait for the 1st operation to complete, before you start the 2nd one. If for example: 1st operation succeeds all the time, then it's well and good, your delay logic will work, but if the 1st operation fails for reasons like network unavailability or any unknown reasons. Then after the delay period your second logic makes the assumption the 1st one is succeeded and starts performing some steps. You need to rethink and design your solution in a different way so that you can avoid this conflict.

Regards,
Saravana
Tuesday, March 27, 2007 10:10 PM
Anonymous
Anonymous
Hi Saravana,

My name is Bhaskar and am part of the BizTalk Server product team at Microsoft. I realize this is kinda late in the cycle but we acknowledge this issue with SQL adapter and unfortunately since we are close to BizTalk Server 2006 R2 release, we cannot fix it as part of this release. We are however documenting this issue as a known issue with SQL Adapter configuration in our R2 release documents.

Thanks for posting this since we are always on the lookout for valuable customer feedback.

Bhaskar
Thursday, April 05, 2007 7:47 PM
Saravana
Hello Saravana
We are using biztalk 2006 sql adapter to fetch data from SQL server.But the sql wizard closes with out throwing any error after i completing the section select store procedure and generate.Could you please explain why this occurs.My data type does not contain any of the follwing types
varbinar(max) or varchar(max) or nvarchar(max) or xml which will fail sql 2005.Any suggestions on this greatly appreicated
Thanks
Saravana Ramkumar
Monday, April 09, 2007 11:21 PM
Saravana
Iam following up with my previous comment on the SQL adapter wizard Weird problem.We are using 64 bit Amd processor biztalk server 2006 /SQL 2005.The SQL Adapter in 2006 isnt compatabile with 64 bit M/c installed Biztalk servers.Sql Adapter will not run on 64 bit machines ,so we need to create one more host instance to have 32 bit for the SQL adapter.Please find the article below
msdn2.microsoft.com/en-us/library/aa560166.aspx
Sunday, February 17, 2008 7:56 PM
Anonymous
Anonymous
hi, link given in ur reply does not contain any article..or may be i could not find...any help please
Sunday, February 17, 2008 8:06 PM
Anonymous
Anonymous
really sorry i was wrong,,,sorry again

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading