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

Got a socket init error #2

xinqiyang opened this issue Sep 18, 2013 · 3 comments

Got a socket init error #2

xinqiyang opened this issue Sep 18, 2013 · 3 comments


Copy link

@xinqiyang xinqiyang commented Sep 18, 2013


I follow to try to make a demo,but when i connect to server ,it got socket init error.

nginx version: ngx_openresty/

Nginx Log :
2013/09/18 00:32:13 [error] 6245#0: *3 lua entry thread aborted: runtime error: /usr/local/lualib/resty/websocket/server.lua:105: expecting zero arguments, but got 1
stack traceback:
coroutine 0:
[C]: in function 'req_sock'
/usr/local/lualib/resty/websocket/server.lua:105: in function 'new'
[string "content_by_lua"]:3: in function <[string "content_by_lua"]:1>, client:, server:, request: "GET /1.0/websocket HTTP/1.1", host: ""

nginx conf:
worker_processes 2;

error_log logs/error.log;

events {
worker_connections 10240;

http {
include mime.types;

default_type  application/octet-stream;


server_tokens off;

server_names_hash_bucket_size 128;
client_body_buffer_size 4m;
client_max_body_size 300m;
large_client_header_buffers 2 1k;

client_body_timeout   3;
client_header_timeout 3;
keepalive_timeout     5;
send_timeout          5;    

sendfile on;
tcp_nopush     on;
tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;

gzip on;
gzip_min_length  1k;
gzip_buffers     4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_vary on;

#close lua code cache, if is product please open .
lua_code_cache off;

gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

lua_shared_dict haddit_shared_dict 300m;
#add websocket lib 
lua_package_path "/usr/local/lualib/resty/websocket/?.lua;;";

# add firewall
init_by_lua_file conf/waf/init.lua;
access_by_lua_file conf/waf/waf.lua;    

include vhosts/*.conf;


log_format yagamiko '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_cookie" $http_x_forwarded_for';

server {
listen 80 so_keepalive=2s:2s:8;

    encrypted_session_key       "asdfghjklqasdfghjklqasdfghjklqwe";
    encrypted_session_iv        "12345678123456";
    encrypted_session_expires   30d;

    #static file directory
    location ~ ^/(static|media)/ {
        root    '__YAGAMI_APP_PATH_VALUE__/static';
        expires 30d;

    location /1.0/websocket {
          lua_socket_log_errors off;
          lua_check_client_abort on;
          content_by_lua '
            local server = require "resty.websocket.server"
            local wb, err = server:new{
                timeout = 5000,  -- in milliseconds
                max_payload_len = 65535,
            if not wb then
              ngx.log(ngx.ERR, "failed to new websocket: ", err)
              return ngx.exit(444)
            while true do
              local data, typ, err = wb:recv_frame()
              if wb.fatal then
                ngx.log(ngx.ERR, "failed to receive frame: ", err)
                return ngx.exit(444)
              if not data then
                local bytes, err = wb:send_ping()
                if not bytes then
                  ngx.log(ngx.ERR, "failed to send ping: ", err)
                  return ngx.exit(444)
              elseif typ == "close" then break
              elseif typ == "ping" then
                local bytes, err = wb:send_pong()
                if not bytes then
                  ngx.log(ngx.ERR, "failed to send pong: ", err)
                  return ngx.exit(444)
              elseif typ == "pong" then
                ngx.log(ngx.INFO, "client ponged")
              elseif typ == "text" then
                local bytes, err = wb:send_text(data)
                if not bytes then
                  ngx.log(ngx.ERR, "failed to send text: ", err)
                  return ngx.exit(444)

    #lua_code_cache off;
    location / {
        #default_type text/html;
        set $YAGAMI_HOME      '__YAGAMI_HOME_VALUE__';

        #set $wdfsproxy $uri;
        #load yagami
        content_by_lua_file     '$YAGAMI_HOME/luasrc/yagami.lua';

    #location /weedfsproxy {

    #set error
    #error_page   500 502 503 504  /50x.html;
    #location = /50x.html {
    #    root   html;

    access_log  /freeflare/trunk/foundation/server/lua/yagamiko/nginx_runtime/logs/__YAGAMI_APPNAME_VALUE__.log  yagamiko;
    error_log  /freeflare/trunk/foundation/server/lua/yagamiko/nginx_runtime/logs/__YAGAMI_APPNAME_VALUE___err.log  debug;

This comment has been minimized.

Copy link

@agentzh agentzh commented Sep 18, 2013

@xinqiyang you didn't look closer enough :)

You need the "websocket" git branch in the ngx_lua github repository for now because this thing is not yet merged into the master branch nor getting included in any ngx_openresty releases.

To quote the related part in that blog post:

$ git clone
$ cd lua-nginx-module
$ git checkout -b websocket origin/websocket
$ cd ../ngx_openresty-
$ rm -Rf ngx_lua-0.8.9
$ ln -s ../../lua-nginx-module ngx_lua-0.8.9

Anyway, I'm going to merge the websocket branch into master in the next few days or so.



This comment has been minimized.

Copy link

@xinqiyang xinqiyang commented Sep 19, 2013

@agentzh Thank you ....
I'll try it again.


This comment has been minimized.

Copy link

@xinqiyang xinqiyang commented Sep 20, 2013

I test success.
more, please visit: (chinese)

@agentzh,Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.