-
Notifications
You must be signed in to change notification settings - Fork 272
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
ngx.socket.tcp cannot send msg to logstash #142
Comments
duplicate cloudflare/lua-resty-logger-socket#29 |
@anjia0532 Do you see anything in the nginx error log file? BTW, you can see more details when the nginx debugging logs are enabled. |
not error log,by the tcpdump log ngx.socket.tcp are sended msg.
the chinese IT blog http://m.blog.csdn.net/chenlycly/article/details/52402945 TCP Dup ACK the |
ping @agentzh , local ok, err = sock:setkeepalive(1000, 100) -- zero cannot send msg to logstash , timeout value must be >0 it worked. |
@anjia0532 The first argument of setkeepalive should never ever to zero. It's the max idle time in the connection pool. |
@anjia0532 Read the documentation. |
Hmm, it seems that zero actually means unlimited. Then there might be other things going on here. |
yup,i read ngx.socket.tcp doc ,logstash doc and codec plugin source, but not helpful,my english is not good, i posted this issues to chinese email list https://groups.google.com/forum/?nomobile=true#!topic/openresty/icx9jcR6Ja0 |
@anjia0532 Maybe you should try using nc on the other side to receive the TCP data? Not sure if it's something specific to your logstash server. Maybe your logstash server may send some data back, which is not expected by your Lua client code code nor the cosocket connection pool. |
@anjia0532 I just tried your code example on my side and everything works as expected: location / {
content_by_lua '
local sock,err = ngx.socket.tcp()
if not sock then
ngx.say("init socket has error : ",err)
else
ngx.say("init socket is ok")
end
local ok, err = sock:connect("127.0.0.1", 5044)
if not ok then
ngx.say("create connect has error : ",err)
else
ngx.say("create connect is ",ok)
end
local bytes, err = sock:send("this is test msg")
if not bytes then
ngx.say("socket send msg has error : ",err)
else
ngx.say("sended bytes size: " ,bytes)
end
local ok, err = sock:setkeepalive(0, 100)
if not ok then
ngx.say("set keepalive has error : ",err)
else
ngx.say("set keepalive is ",ok)
end
';
} And then I use nc to listen on the local 5044 port with the following shell command:
Then I do a request to the $ curl localhost:8080/
init socket is ok
create connect is 1
sended bytes size: 16
set keepalive is 1 And on the terminal running nc, I've got
The test was performed on a Linux box (Fedora 24 x86_64) with the latest OpenResty. |
@anjia0532 Running curl for multiple times also works as expected:
|
Thank you very much for your patience. looks like logstash server's reason |
$ nc -l -k 5044
$ echo "this is test msg" | telnet 127.0.0.1 5044
#nc output
--
this is test msg
<- there has line break
--
$ curl localhost
#nc output
--
this is test msg <- no line break
-- it will auto append line break to msg when telnet send msg. i agree with u ,this is logstash server's reason. not ngx.socket.tcp |
env
host
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
logstash version 5.5.2
openresty version 1.11.2.5
openresty configure params
nginx.conf
logstash conf named
demo.conf
./bin/logstash -f demo.conf
wait for outputSuccessfully started Logstash API endpoint {:port=>9600}
logstash console can't output anything,
wireshark has many
tcp dup ack
andtcp Out-Of-Order
info.logstash console output
Ctrl+] and Ctrl+D exit telnet
logstash output msg
The text was updated successfully, but these errors were encountered: