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

client closed prematurely connection while reading client request line #101

Closed pokal4u closed 11 years ago

pokal4u commented 11 years ago

Hi, I got errors in error_log file like

  1. client closed prematurely connection while reading client request line
  2. too many connections
  3. recv() failed (104: Connection reset by peer)

4.client closed keep alive connection

This time get 500 internal server error

we are using ubuntu and my config file:

pid logs/nginx.pid; error_log logs/nginx-main_error.log debug;

Development Mode

master_process off; daemon off; worker_rlimit_core 500M; working_directory /tmp/nginx;

worker_processes 2; worker_rlimit_nofile 50000;

events { worker_connections 1024; use epoll; }

http {

index index.php index.htm index.html .php;
include         /usr/local/nginx/conf/mime.types;
default_type    application/octet-stream;

access_log      logs/nginx-http_access.log;
error_log       logs/nginx-http_error.log debug;    

tcp_nopush                      off;
tcp_nodelay                     on;
keepalive_timeout               100;
send_timeout                    10;
client_body_timeout             60;
client_header_timeout           60;
sendfile                        on;
client_header_buffer_size       1k;
large_client_header_buffers     8 512k;   
ignore_invalid_headers          on;

push_stream_shared_memory_size              500m;
push_stream_max_channel_id_length           200;
# max messages to store in memory
push_stream_max_messages_stored_per_channel  1000;
# message ttl
push_stream_message_ttl                      2s;
# ping frequency
push_stream_ping_message_interval           10s;
# connection ttl to enable recycle
push_stream_subscriber_connection_ttl        15m;
# connection ttl for long polling
push_stream_longpolling_connection_ttl        5m;
# broadcast
push_stream_broadcast_channel_prefix        "broad_";

#push_stream_message_template                "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"eventid\":\"~event-id~\"}";
push_stream_message_template                "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\"}";

# subscriber may create channels on demand or only authorized
# (publisher) may do it?
push_stream_authorized_channels_only        off;
push_stream_broadcast_channel_max_qtd       3;

client_max_body_size                    3M;
client_body_buffer_size                 3M;
proxy_buffering off;
proxy_ignore_client_abort on;

gzip  on;
gzip_static on;
gzip_min_length  1100;
gzip_buffers     16 400k;
gzip_proxied     any;
gzip_types       text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript text/plain;
gzip_comp_level  9;
gzip_http_version   1.0;

access_log off;

server { listen 80 default_server;
server_name localhost;
.................... .......................... } } Please help me Pokal

wandenberg commented 11 years ago

Hi @pokal4u,

What kind of connections are you using? (eventsource, websocket, stream, long polling, ...) What client are you using? Are you using the pushstream.js?

The messages 1 and 4 are common to receive, but may be in a higher number due to your configuration. Mainly by using development mode (master_process and daemon as off) The other two are probably configuration issues.

pokal4u commented 11 years ago

Hi,

I am using longpooling connection and pushstream.js

Thanks Pokal

wandenberg commented 11 years ago

The default longpolling timeout on pushstream.js is 30s, if you do not have changed that value, you are using incompatible values between client (30s) and server (5m), use a value slightly bigger on client, like 60s on sever and 65s on client. With this adjust probably your error messages will decrease. And do not use development mode on production. ;)

wandenberg commented 11 years ago

Any news?

pokal4u commented 11 years ago

Hi, Thanks

9992800 commented 8 years ago

I got same problem and I am using websocket.this is my conf

user nobody;

worker_processes 4;

error_log logs/error.log;

error_log logs/error.log notice;

error_log logs/error.log info;

pid logs/nginx.pid;

events { worker_connections 65535; }

http { include mime.types; default_type application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent [$request_body] '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  logs/access.log  main;

log_escape_non_ascii off;

push_stream_shared_memory_size                1500M;
push_stream_max_channel_id_length             256;
push_stream_max_messages_stored_per_channel   5;

push_stream_authorized_channels_only on;

push_stream_message_ttl                      24h;
lua_package_path "/data/openresty/lualib/resty/?.lua;;";

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  65;

#gzip  on;

server {
    listen           9080 default_server;

    charset utf-8;

    access_log  logs/host.access.log  main;

    #lua_code_cache off;

    location /ios_push{
            lua_need_request_body on;
            content_by_lua_file  conf/memcached.lua;
    }

    location /android_push {

            push_stream_publisher admin;

            push_stream_channels_path               $arg_id;

            push_stream_store_messages              on;
    }

    location ~ /ws/(.*) {

            push_stream_subscriber websocket;

            push_stream_channels_path                   $1;

            push_stream_last_received_message_time      "$arg_time";
            push_stream_last_received_message_tag       "$arg_tag";

            push_stream_message_template                 "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":~text~,\"tag\":~tag~,\"time\":\"~time~\"}"; 

            push_stream_websocket_allow_publish         on;

            push_stream_ping_message_interval           180s;

            push_stream_store_messages              on;
    }

    location /channels-stats {
        # activate channels statistics mode for this location
        push_stream_channels_statistics;

        # query string based channel id
        push_stream_channels_path               $arg_id;
    }
}

}

and also I push about 500 messages/second to the location "/android_push"

What can I do for this situation ?Thanks

wandenberg commented 8 years ago

What is your exactly situation?

9992800 commented 8 years ago

I used websocket to pull message and I got these 2 errors. 1,recv() failed (104: Connection reset by peer) 2,client closed prematurely connection while reading client request line

many users can't connect to " location ~ /ws/(.*)" and at the same time I used another to send push message to “ location /android_push ” and the speed is about 500 messages/second.

I think maybe it's too fast to push so many messages to the "location /android_push " and the connections of nginx are used up.

Am I clear?

wandenberg commented 8 years ago

@9992800 these messages are not produced by the module itself. Considering the scenario you have described I would say that the problem is a network/socket configuration at your server. You must tune socket buffers sizes and number of max open files to correspond to the number of worker connections that you are setting, specially if are starting the server as a "normal" user. Many of the OSs have a low value, like 128 or 1024 for max open files by default. There are some tutorials about these configurations and tunes for nginx.

9992800 commented 8 years ago

Ok ,thanks very much ,I will try.thanks again