2

I have an Asp.net MVC application running on AppHarbor. It has the everyday email ordering process:

  1. User enters their email and submits it.
  2. System processes order and sends out email with a link.
  3. 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));
}
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
  • 1
    @marc_s I updated my question a bit... I'm talking about `datetime` SQL data type of course. Sorry for not making it clear enough. – Robert Koritnik Mar 29 '12 at 20:47
  • Since the SQL Server `DATETIME` datatype has an accuracy of 3.33ms - it's entirely possible to have two entries with the same value in there – marc_s Mar 30 '12 at 04:50

1 Answers1

1

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.

usr
  • 168,620
  • 35
  • 240
  • 369
  • That is exactly what I anticipated that's why I also explained the scenario of the app going down and then back up. I also thought of the same scenario, just found it a bit hard to believe since there's really low traffic. But it does widen the window when the app starts... – Robert Koritnik Mar 29 '12 at 20:50