wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.22k stars 295 forks source link

Always flush buffers after sending a message #112

Closed dctrwatson closed 9 years ago

dctrwatson commented 10 years ago

Fixes issue of NGX_AGAIN when terminating chunk isn't sent (mainly when sending messages via HTTPS)

dctrwatson commented 10 years ago

Hrm, this is actually not well placed to handle more than my very specific conditions in which I'm hitting this issue

quentinsf commented 10 years ago

Many thanks! This fixed a problem of mysteriously empty responses from the server.

Greatly appreciated!

wandenberg commented 10 years ago

Hi @dctrwatson and @quentinsf ,

I was looking the pull request and also the patch @dctrwatson sent do nginx-devel list. Just to be sure, they are related, right?

Can you help me understand a bit better what is happening and how to reproduce? I know that the module close the connection if the nginx answer with a NGX_AGAIN, and want to do a better treatment to this. But this patch has two problems.

It always allocate a new buffer in request pool, which will be released only when the connection closes. This is a small structure, but multiplied by the number of times that this happens and the number of users connected to the server can be a big problem.

ngx_http_send_special(ngx_http_request_t *r, ngx_uint_t flags)
{
    ngx_buf_t    *b;
    ngx_chain_t   out;

    b = ngx_calloc_buf(r->pool); 

The other problem in fact is that I didn't understand what is the difference between what I already do, since I set the buffer to be flushed on ngx_http_push_stream_send_response_text function, and the use of ngx_http_send_special function.

May be that the problem itself was solved with the patch John applied on nginx chunked filter.

I really need your help to understand the problem and how to reproduce it here to do a proper solution. Together I'm sure we can find a solution.

wandenberg commented 9 years ago

Hi @dctrwatson and @quentinsf

can you test the code on fix_ngx_again_on_read_and_write branch (commit df6b37a). It should solve the problem with the ngx_again without use the ngx_http_send_special function which allocates extra memory.

wandenberg commented 9 years ago

Fixed with a48ca949427b782fba1722932f4881850c50b9f1