I found the problem. I start mojolicious in prefork mode with several 
workers. When Mojolicious reforks workers, he resets the connections of 
this worker. I start this in daemon single process mode, and everything is 
ok.
Is it normal then mojolicious reset connections of worker?

среда, 15 октября 2014 г., 10:45:23 UTC+4 пользователь [email protected] 
написал:
>
> I have nginx with following config:
>
> map $http_upgrade $connection_upgrade {
>     default upgrade;
>     '' close;
> }
>
>
> server {
>     listen 80;
>     server_name mydomain.com;
>     location / {
>         proxy_pass http://127.0.0.1:3000/;
>         proxy_set_header   Host             $host;
>         proxy_set_header   X-Real-IP        $remote_addr;
>         proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
>         proxy_set_header   ssl              $ssl_protocol;
>         proxy_http_version 1.1;
>         proxy_set_header    Upgrade $http_upgrade;
>         proxy_set_header    Connection $connection_upgrade;
>         proxy_read_timeout  65s;
>     }
> }
>
>
> I have the following websocket server:
>
> use Mojolicious::Lite;
> use Mojo::Redis;
> use Mojo::IOLoop;
>
> websocket '/' => sub {
>     my $self = shift;
>     $self->inactivity_timeout(65);
>     my $pub = Mojo::Redis->new;
>     my $sub = $pub->subscribe('test');
>     my $w = Mojo::IOLoop->recurring(60 => sub {
>         $self->send([1, 0, 0, 0, 9, 'PING']);
>     });
>
>     $sub->on(message => sub {
>         my ($sub, $message, $channel) = @_;
>         $self->send($message . ' ' . time);
>     });
>
>     $self->on(message => sub {
>         my ($conn, $msg) = @_;
>         $conn->send("echo: $msg");
>     });
>
>     $self->on(finish => sub {
>         undef $self;
>         undef $pub;
>         undef $sub;
>         Mojo::IOLoop->remove($w);
>     });
> };
> app->start;
>
> And i have following js code:
>
> var socket = new WebSocket("ws://mydomain.com")
>
> soket.onopen = function() { 
>   console.log("Connection established"); 
> }
>
> socket.onclose = function(event) {
>  if (event.wasClean) {
>    console.log('Connection was closed cleanly');
>  }
>  else {
>    console.log('Connection reseted');
>  }
>  console.log('Code: ' + event.code + ' Reason: ' + event.reason);
> };
>
> socket.onmessage = function(event) {
>   console.log('Recieved data: ' + event.data);
> };
>
> socket.onerror = function(error) {
>  console.log('Error: ' + error.message);
> }
>
> And after 10 minutes i have reset connection with code 1006. This is the 
> messages in browser console:
> [ws://mydomain.com] Connection established 
> [ws://mydomain.com] Connection reseted
> [ws://mydomain.com] Code: 1006 Reason:  
>
> I tried to change inactivity_timeout in mojolicious and proxy_read_timeout 
> in nginx and it didn't help.
> Please help me to understand, what i doing wrong.
> Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to