I have an Asp.net MVC application running on AppHarbor. It has the everyday email ordering process:
- User enters their email and submits it.
- System processes order and sends out email with a link.
- User checks email and clicks the link to do the next step…
The thing is that between steps #2 and #3 a lot of time can pass. Some users check their emails immediately, others after a day or even later. The main thing is that enough time can pass that the application on the server ends.
So when the user clicks a link it may mean that they will have to wait for a bit for the application to start back up…
Question
When step #3 processes a record in database is updated with a timestamp (type is datetime of course) when step #3 took place. But grok this: I can see records with completely identical timestamps! How can that even happen?
Timestamp gets generated in application layer and then pushes the updated to database. I’m using PetaPoco for data access.
What can cause multiple records to record the same time? My application has such small traffic that it actually does shut down sometimes during day so I find it hard to believe that multiple (up to three) users did step #3 at exactly the same time. And since this is running on a single process I suppose it’s impossible…
What can be the cause for this?
Update code is really really simple
using (var db = this.DataContext)
{
db.Execute(Sql
.Builder
.Append("update dbo.SteppedProcess set Step3ProcessedOn = @0", DateTime.Now)
.Where("Step3ProcessedOn is null")
.Where("Id = @0", id));
}
ASP.NET is running multiple threads, even on a single CPU. So this could happen. I guess it is more like to happen in your case because after the app has shut down, it needs to start up. All request coming in during the startup phase are queued and executed immediately and simultaneously once your app becomes available. This opens up a bigger window of opportunity.
And because the Windows clock has about 15ms resolution, there is a big chance that simultaneous request will get the same timestamp.