ancruna / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

HTTP GET connections are served before POST #329

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using authentication digest with mongoose and geting funy results with 
mainly opera and firefox.

I'm checking the "nc" (nounce count) on every connection to see if it has the 
expected value (last "nc"+1), but when I make two requests sequentially one 
through POST and the second through GET the browser send then in the correct 
order and with the "nc" field with correct values, but somehow when processed 
by mongoose it seems that the GET request is parsed in less time than the POST 
and sent to my application that see a mismatch on the "nc" field.

I'm not sure how this can be solved !

Browser:
POST -> nc=5
GET  -> nc=6

mongoose seems to parse GET faster

My application:
GET  -> nc=6   << here I issue a 401 because I expect nc=5
POST -> nc=5   << here too

Original issue reported on code.google.com by mingo...@gmail.com on 26 Mar 2012 at 10:19

GoogleCodeExporter commented 9 years ago
Looking at the final representation of the connection sequence it seems like 
the processing order is last in first out.

Original comment by mingo...@gmail.com on 26 Mar 2012 at 10:22

GoogleCodeExporter commented 9 years ago
On this secction of code:

  // Wrap pointers if needed
  while (ctx->sq_tail > (int) ARRAY_SIZE(ctx->queue)) {
    ctx->sq_tail -= ARRAY_SIZE(ctx->queue);
    ctx->sq_head -= ARRAY_SIZE(ctx->queue);
  }

Do we expect to iterate more than once ?
An if isn't enough ?

Original comment by mingo...@gmail.com on 26 Mar 2012 at 10:42

GoogleCodeExporter commented 9 years ago
Also on this section of code:

// Copy socket from the queue and increment tail
  *sp = ctx->queue[ctx->sq_tail % ARRAY_SIZE(ctx->queue)];

Why "ctx->sq_tail % ARRAY_SIZE(ctx->queue)" ?
We expect ARRAY_SIZE to be smaller than ctx->sq_tail ?
If not, this isn't be enough "*sp = ctx->queue[ctx->sq_tail];" ?

Original comment by mingo...@gmail.com on 26 Mar 2012 at 10:57

GoogleCodeExporter commented 9 years ago
Also here and in other places that do the same:

if (ctx->sq_head - ctx->sq_tail < (int) ARRAY_SIZE(ctx->queue)) {
  // Copy socket to the queue and increment head

Why "ctx->sq_head - ctx->sq_tail" ?
This isn't enough "if (ctx->sq_head < (int) ARRAY_SIZE(ctx->queue)) " ?

Original comment by mingo...@gmail.com on 26 Mar 2012 at 11:06

GoogleCodeExporter commented 9 years ago
Unless requests are pipelined, which is not in you case I think, they are going 
to be processed by separate threads. This means, there is no order guarantee 
whatsoever, cause there is no such thing as processing order. Requests are 
getting into the socket queue in one order, but picked up by different threads.
Since GET request is cheaper to process, there should be no surprise it is 
executed faster.

Original comment by valenok on 27 Mar 2012 at 12:57