Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of uninitialized value in sprintf at .../Kelp.pm line 149. #3

Closed
vfilatov opened this issue May 2, 2013 · 4 comments
Closed

Use of uninitialized value in sprintf at .../Kelp.pm line 149. #3

vfilatov opened this issue May 2, 2013 · 4 comments
Assignees

Comments

@vfilatov
Copy link

vfilatov commented May 2, 2013

The app is being accessed with nginx.
$req->address is an 'undef' value in Kelp.pm while sprintf has to print it...
It is not critical...

$ plackup -E development -s Starman -l /apps/log/WS.sock -a app.psgi
2013/05/02-15:26:48 Starman::Server (type Net::Server::PreFork) starting! pid(15202)
Binding to UNIX socket file "/apps/log/WS.sock"
Setting gid to "65199 65199 115 65199"
Starman: Accepting connections at http://localhost:/apps/log/WS.sock/

Use of uninitialized value in sprintf at /apps/perl-lib/lib/perl5/Kelp.pm line 149. <<<

  • - - [02/May/2013:15:30:10 -0400] "GET /WS/qwerty HTTP/1.0" 200 74 "-" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31"
@ghost ghost assigned sgnix May 2, 2013
@sgnix
Copy link
Collaborator

sgnix commented May 2, 2013

It sounds like this is a problem with your nginx configuration. Do you have the following line in your nginx proxy configuration? proxy_set_header X-Real-IP $remote_addr;

Look at http://wiki.nginx.org/HttpProxyModule for more information on how to set up your proxy, but generally the http section in your nginx config should look something like this:

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

    sendfile        on;
    keepalive_timeout  65;

    upstream kelp {
        server 127.0.0.1:5000;
    }

    server {
        listen       80;
        server_name  localhost;

        root         /srv;
        error_log    off;
        access_log   off;

        location / {
            proxy_read_timeout 300;
            proxy_pass http://kelp;

            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-HTTPS 0;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }

}

Notice the last 4 lines in location. They forward some headers from nginx over to your Kelp app.

I might add a condition to handle this warning within Kelp's code, but it seems that it may be useful, because it lets you know that your app is not receiving the correct headers from nginx.

@vfilatov
Copy link
Author

vfilatov commented May 2, 2013

Yes, I do have those lines in nginx.conf

Would you try please replace
upstream kelp { server 127.0.0.1:5000; }
with
upstream kelp { server unix:/tmp/kelp.sock; }
and run the app as
$ plackup -s Starman -l /tmp/kelp.sock -a your_app.psgi

On Thu, May 2, 2013 at 7:44 PM, Stefan Geneshky notifications@github.comwrote:

It sounds like this is a problem with your nginx configuration. Do you
have the following line in your nginx proxy configuration: proxy_set_header
X-Real-IP $remote_addr;

Look at http://wiki.nginx.org/HttpProxyModule for more information on how
to set up your proxy, but generally the http section in your nginx config
should look something like this:

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

sendfile        on;
keepalive_timeout  65;

upstream kelp {
    server 127.0.0.1:5000;
}

server {
    listen       80;
    server_name  localhost;

    root         /srv;
    error_log    off;
    access_log   off;

    location / {
        proxy_read_timeout 300;
        proxy_pass http://kelp;

        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-HTTPS 0;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

}

Notice the last 4 lines in location. They forward some headers from nginx
over to your Kelp app.

Also, note that the "development" mode in Plack is called "deployment", so
your plackup command should look like this:

$ plackup -E deployment -s Starman -l /apps/log/WS.sock -a app.psgi

I might add a condition to handle this warning within Kelp's code, but it
seems that it may be useful, because it lets you know that your app is not
receiving the correct headers from nginx.


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-17371605
.

@vfilatov
Copy link
Author

vfilatov commented May 3, 2013

REMOTE_ADDR is not there if you proxying request through socket...

As a workaround I use

sub request {
my ( $self, $env ) = @_;
$env->{ REMOTE_ADDR } ||= $env->{ HTTP_X_REAL_IP };
return Kelp::Request->new( env => $env );
}

@sgnix
Copy link
Collaborator

sgnix commented May 3, 2013

Yes, you are correct. I will add a patch for this in the next Kelp release. It seems like it might be a Plack issue, though. There are other headers that are not properly forwarded, for example REMOTE_HOST.

sgnix pushed a commit that referenced this issue May 3, 2013
@sgnix sgnix closed this as completed May 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants