Followup to a previous related topic now that I have a few more details.
We've been having issues with part of our home-grown CMS.
Whenever a page is edited, and saved, we do a recursive call to the DB and
then spit out an XML file to build the site map, which is then published to
the site.
We ran into an issue that we believe (as we can't replicate it) is happening
when two people manage to hit SAVE at the exact same time, causing two
processes to try writing to the exact same XML file at the same time. This
appears to cause the XML file to only be half-written (my theory that the
second process interupts the first and then they both fail).
This is what we originallly had:
objXMLWriter = New
System.xml.XmlTextWriter(System.Web.HttpContext.Cu rrent.Server.MapPath("/mjb05/xml/"
& siteID & "/siteMenu.xml").ToString, Nothing)
It was suggested that we lock the file as we write it, preventing any
further edits from another process until the first process is done with it:
Dim fs As New
System.IO.FileStream(System.Web.HttpContext.Curren t.Server.MapPath("/mjb05/xml/"
& siteID & "/siteMenu.xml").ToString, IO.FileMode.Open, IO.FileAccess.Write,
IO.FileShare.Read)
objXMLWriter = New System.xml.XmlTextWriter(fs, Nothing)
However, this causes a new problem. Not every time, but usually every other
time or so, when the XML is written, the entire XML file is written
correctly, but then some 'extra crap' is tacked onto the end...typically a
repeat of a few nodes split in the middle of a tag. Which, obviously, is
causing the XML that is being written to be invalid.
Any thoughts on what is happening and/or why and/or a fix/workaround?
The only thing I've been able to come up with is to have the function write
the XML, and then use another function to open the file back up again, and,
then using some string functions, trim off anything after the last closing
node, then resave. That, of course, is a huge hack, so less than idea.
I've also discovered that the problem ONLY happens when i do the recursion.
If I just run through the function once, I can not get it to write the bad
XML. Not sure HOW that is related, but it's something else I've been able to
observe.
Any thoughts appreciated!
-Darrel