dpull / lua-webclient Goto Github PK
View Code? Open in Web Editor NEWNonblocking lua http library.
License: MIT License
Nonblocking lua http library.
License: MIT License
我用nginx挂了一个test.php。里面就一句。 浏览器访问能正常显示“hello”字符串。但是skynet.call("webclient", "lua", "request", "http://localhost/test.php")的时候,会在webclient.lua的第37行(xpcall那一句)报错。
遇到了这个issues中同样的问题,加入链接-lcurl后仍然报错
#8
undefined symbol: curl_easy_escape
已解决,在这里补充一下,链接的时候要把-lcurl加在后面,像这样:
cc -g -O2 -Wall -Iskynet/3rd/lua -fPIC --shared -Iserver/lualib-src/webclient server/lualib-src/webclient.c -o server/luaclib/webclient.so -lcurl
如果是这样把链接库选项加在中间则会报错:
cc -g -O2 -Wall -Iskynet/3rd/lua -fPIC --shared -Iserver/lualib-src/webclient -lcurl server/lualib-src/webclient.c -o server/luaclib/webclient.so
附一个参考makefile:
include platform.mk
LUA_CLIB_PATH ?= server/luaclib
LUA_CLIB = webclient
CFLAGS = -g -O2 -Wall -I$(LUA_INC) $(MYCFLAGS)
# lua
LUA_STATICLIB := skynet/3rd/lua/liblua.a
LUA_LIB ?= $(LUA_STATICLIB)
LUA_INC ?= skynet/3rd/lua
all : \
$(foreach v, $(LUA_CLIB), $(LUA_CLIB_PATH)/$(v).so)
$(LUA_CLIB_PATH)/webclient.so : server/lualib-src/webclient.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -Iserver/lualib-src/webclient $^ -o $@ -lcurl
可关闭该issues或保留作为参考
skynet中使用, 报以下错误:
:00000018(1486429408.35)[2017-02-07 09:03:28]: lua loader error : error loading module 'webclient' from file './luaclib/webclient.so':
./luaclib/webclient.so: undefined symbol: curl_easy_escape
stack traceback:
[C]: in ?
[C]: in function 'require'
./mainserver/webclient.lua:7: in local 'main'
./skynet/lualib/loader.lua:48: in main chunk
:00000018(1486429408.35)[2017-02-07 09:03:28]: KILL self
:00000008(1486429408.35)[2017-02-07 09:03:28]: init service failed: ./skynet/lualib/skynet.lua:535: ./skynet/service/service_mgr.lua:25: ./skynet/lualib/skynet.lua:381: call failed
stack traceback:
[C]: in function 'assert'
./skynet/lualib/skynet.lua:535: in function 'skynet.uniqueservice'
./mainserver/main.lua:15: in local 'start'
./skynet/lualib/skynet.lua:619: in function <./skynet/lualib/skynet.lua:616>
[C]: in function 'xpcall'
./skynet/lualib/skynet.lua:623: in function 'skynet.pcall'
./skynet/lualib/skynet.lua:627: in function 'skynet.init_service'
./skynet/lualib/skynet.lua:640: in upvalue 'f'
./skynet/lualib/skynet.lua:104: in function <./skynet/lualib/skynet.lua:103>
具体是webclient_destory函数里的curl_multi_cleanup。
用skynet.abort关闭,有时候会报错。
➜ CardGameHall git:(develop) ✗ curl --version
curl 7.35.0 (x86_64-pc-linux-gnu) libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP
CURLOPT_POSTFIELDS 在7.17.1版本以后不会拷贝post数据
另外新增了一个选项:CURLOPT_COPYPOSTFIELDS
提此issue,希望后面使用这个库的同学不要掉坑了...
我将test.lua中urls改成https://api.mch.weixin.qq.com/pay/unifiedorder,运行出现Resolving timed out
https://api.mch.weixin.qq.com/pay/unifiedorder 0 Resolving timed out after 5000 milliseconds 0 -1.0 0
但是同一台机器用curl能返回结果:
curl -f https://api.mch.weixin.qq.com/pay/unifiedorder
<return_code></return_code><return_msg></return_msg>%
from: lgc
发起一个https请求,服务器没有返回content-length回导致你的库拿不到正确的结果
比如说这个网站:https://www.ddpkcc.com/
curl -I https://www.ddpkcc.com
HTTP/1.1 200 OK
Server: nginx/1.11.13
Date: Wed, 30 Aug 2017 09:32:58 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/7.0.20
偶尔出现的情况
skynet中使用webclient
生产环境:
Linux VM-16-11-ubuntu 4.15.0-142-generic
curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0
OpenSSL 1.0.2g 1 Mar 2016
比较奇怪的地方:
libcurl 第三方库为啥会调用到 skynet-src/malloc_hook.c 的free方法
以下是报错堆栈:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 je_san_check_stashed_ptrs (ptrs=0xfffffffffffff9c0, nstashed=nstashed@entry=200, usize=32)
at src/san.c:182
182 src/san.c: No such file or directory.
[Current thread is 1 (Thread 0x7fc0b9bef700 (LWP 28184))]
(gdb) where
#0 je_san_check_stashed_ptrs (ptrs=0xfffffffffffff9c0, nstashed=nstashed@entry=200, usize=32)
at src/san.c:182
#1 0x00000000004be120 in je_tcache_bin_flush_stashed (is_small=true, binind=2, cache_bin=0x7fc0b9bef048,
tcache=0x7fc0b9bef010, tsd=0x7fc0b9beecb8) at src/tcache.c:570
#2 tcache_bin_flush_bottom (small=true, rem=100, binind=2, cache_bin=0x7fc0b9bef048, tcache=0x7fc0b9bef010,
tsd=0x7fc0b9beecb8) at src/tcache.c:508
#3 je_tcache_bin_flush_small (tsd=tsd@entry=0x7fc0b9beecb8, tcache=tcache@entry=0x7fc0b9bef010,
cache_bin=0x7fc0b9bef048, binind=, rem=100) at src/tcache.c:529
#4 0x000000000044b87c in tcache_dalloc_small (slow_path=false, binind=, ptr=0x7fc265345f80,
tcache=, tsd=) at include/jemalloc/internal/tcache_inlines.h:157
#5 arena_dalloc (slow_path=false, caller_alloc_ctx=, tcache=,
ptr=0x7fc265345f80, tsdn=) at include/jemalloc/internal/arena_inlines_b.h:331
#6 idalloctm (slow_path=false, is_internal=false, alloc_ctx=, tcache=,
ptr=0x7fc265345f80, tsdn=) at include/jemalloc/internal/jemalloc_internal_inlines_c.h:120
#7 ifree (slow_path=false, tcache=, ptr=0x7fc265345f80, tsd=0x7fc0b9beecb8)
at src/jemalloc.c:2887
#8 je_free_default (ptr=0x7fc265345f80) at src/jemalloc.c:3014
#9 0x000000000041fded in free (ptr=0x7fc265345f80) at skynet-src/malloc_hook.c:215
#10 0x00007fc2d176e956 in ?? () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#11 0x00007fc2e0add6ba in start_thread (arg=0x7fc0b9bef700) at pthread_create.c:333
#12 0x00007fc2e00fe51d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
麻烦问下这个库是否有微信昵称中文乱码的解决方案?
作者你好,目前的接口curl连接还是使用阻塞方式,这个能改成非阻塞模式吗?
在拉取依赖的lua版本号时,目标库的版本不存在,请更新依赖的lua版本号,谢谢。
在接入微信官方充值时,调用https请求报错, 如下: NSS: client certificate not found (nickname not specified)。
系统:CentOS Linux release 7.2.1511 (Core)
curl: curl 7.29.0 (x86_64-redhat-linux-gnu)
请求url: https://api.mch.weixin.qq.com/pay/unifiedorder
然而在测试的时候(自己写curl例子测试), 发现这个报错是可以忽略的(在NSS: client certificate not found 报错时,仍然会返回)。
经过定位,发现是 write_callback 时,只要有报错,就return 了:
static size_t write_callback(char* buffer, size_t block_size, size_t count, void* arg)
{
...
//这里return 导致后面没有接受数据
if (webrequest->error[0] != '\0')
return length;
...
}
把这个write_callback和webclient_getrespond的 webrequest->errorr 判断修改后,成功获取到返回(这里我打开了CURLOPT_VERBOSE的调试输出):
* About to connect() to api.mch.weixin.qq.com port 443 (#0)
* Trying 140.207.69.102...
* Connected to api.mch.weixin.qq.com (140.207.69.102) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* skipping SSL peer certificate verification
* NSS: client certificate not found (nickname not specified)
* SSL connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate:
* subject: CN=payapp.weixin.qq.com,OU=R&D,O=Tencent Technology (Shenzhen) Company Limited,L=shenzhen,ST=guangdong,C=CN
* start date: Mar 22 00:00:00 2017 GMT
* expire date: Jun 21 23:59:59 2018 GMT
* common name: payapp.weixin.qq.com
* issuer: CN=GeoTrust SSL CA - G3,O=GeoTrust Inc.,C=US
> POST /pay/unifiedorder HTTP/1.1
Host: api.mch.weixin.qq.com
Accept: */*
Content-Length: 548
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 548 out of 548 bytes
< HTTP/1.1 200 OK
< Server: nginx
< Date: Sat, 01 Apr 2017 06:01:44 GMT
< Content-Type: text/plain
< Content-Length: 454
< Connection: keep-alive
< Keep-Alive: timeout=8
<
* Connection #0 to host api.mch.weixin.qq.com left intact
返回如下
true <xml><return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
...
<trade_type><![CDATA[APP]]></trade_type>
</xml>
如题,使用skynet,如果post的表格中有参数带有布尔值就直接把skynet干掉了。
服务器使用的是skynet框架,最近有时出现崩溃问题,不好重现
收集几个coredump,gdb里看到的都是在webclient_destory的时候触发崩溃
以下是gdb的栈:
(gdb) bt
#0 0x00007fdfdbc1988a in ?? ()
#1 0x00007fdfe942098f in ?? () from /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
#2 0x00007fdfe941ed56 in ?? () from /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
#3 0x00007fdfe942e440 in sk_pop_free () from /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
#4 0x00007fdfe941f0dc in ENGINE_cleanup () from /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
#5 0x00007fdfe01e352e in ?? () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#6 0x00007fdfe01e3ec9 in ?? () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#7 0x00007fdfe01bf695 in curl_global_cleanup () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#8 0x00007fdfe03fe47c in webclient_destory (l=0x7fdfe1b5ed08) at lualib-src/lua-webclient.c:87
#9 0x0000000000414739 in luaD_precall (L=L@entry=0x7fdfe1b5ed08, func=0x7fdfe1a79930, nresults=0) at ldo.c:434
#10 0x0000000000414a03 in luaD_call (L=L@entry=0x7fdfe1b5ed08, func=, nResults=) at ldo.c:498
#11 0x0000000000414a61 in luaD_callnoyield (L=0x7fdfe1b5ed08, func=, nResults=) at ldo.c:509
#12 0x0000000000413e6f in luaD_rawrunprotected (L=L@entry=0x7fdfe1b5ed08, f=0x416010 , ud=0x0) at ldo.c:142
#13 0x0000000000414d4d in luaD_pcall (L=0x7fdfe1b5ed08, func=, u=, old_top=48, ef=) at ldo.c:729
#14 0x0000000000415f1c in GCTM (L=L@entry=0x7fdfe1b5ed08, propagateerrors=propagateerrors@entry=0) at lgc.c:833
#15 0x00000000004175aa in callallpendingfinalizers (L=0x7fdfe1b5ed08) at lgc.c:872
#16 luaC_freeallobjects (L=0x7fdfe1b5ed08) at lgc.c:981
#17 0x000000000041bbce in close_state (L=0x7fdfe1b5ed08) at lstate.c:245
#18 0x000000000041c0c0 in lua_close (L=) at lstate.c:344
#19 0x00007fdfe7dfc7ac in snlua_release (l=0x7fdfe8b79470) at service-src/service_snlua.c:192
#20 0x000000000040abfa in delete_context (ctx=0x7fdfe0991400) at skynet-src/skynet_server.c:213
#21 skynet_context_release (ctx=ctx@entry=0x7fdfe0991400) at skynet-src/skynet_server.c:223
#22 0x000000000040b1fd in skynet_context_message_dispatch (sm=sm@entry=0x7fdfe8a168a0, q=0x7fdfe1b9c500, q@entry=0x0, weight=weight@entry=0) at skynet-src/skynet_server.c:348
#23 0x000000000040b87d in thread_worker (p=) at skynet-src/skynet_start.c:162
#24 0x00007fdfe9e3e184 in start_thread (arg=0x7fdfe2df0700) at pthread_create.c:312
#25 0x00007fdfe907d03d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
请问这可能是什么问题?从哪个方向查?谢谢!
设置cURL允许执行的最长毫秒数无效,超过设定时间后没有返回
看了源码
if (top > 2 && lua_istable(l, 3)) {
http_post = webclient_tohttppost(l, 3);
if (!http_post)
return luaL_argerror(l, 3, "parameter post_form invalid");
}
else if (top > 2 && lua_isstring(l, 3)) {
postdata = lua_tolstring(l,3, &postdatalen);
}
if (top > 3 && lua_isnumber(l, 4)) {
connect_timeout_ms = (long)lua_tointeger(l, 4);
if (connect_timeout_ms < 0)
return luaL_argerror(l, 4, "parameter connect_timeout_ms invalid");
}
源码中if (top > 2 && lua_istable(l, 3)) { 栈上第三个参数如果是table就设置headers,然后下面postdata也是栈上第三个参数,这里是否有误,我理解是url,headers,postdata,timeout。。。这样的排序,现在headers和data是不能同时设置的。
还有就是headers的table格式是什么样的,我这边设置是
local headers = {
["content_type"] = "application/json"
}
实际测试会出现Segmentation fault (core dumped)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.