openresty / openresty/lua-nginx-module
Tcp cosocket receiveuntil call mixed by other reading calls get unexpected result
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 11.8k
- Forks
- 2.1k
- Avg merge
- 6h 1m
- Merged PRs (30d)
- 6
Description
If call receive after receiveuntil when met boundary pattern ambiguity, then call receiveuntil again will return a string which is not a valid subsequence of stream.
Software: v0.10.22 lua module
Config:
location /echo {
return 200 -----abc--abc;
}
location /socket {
default_type 'text/plain';
content_by_lua_block {
local sock = ngx.socket.tcp()
...
local reader = sock:receiveuntil("--abc")
local line, err, part = reader(2)
ngx.say("read 1: ", "[", line, "]")
line, err, part = sock:receive(4)
ngx.say("read 2: ", "[", line, "]")
line, err, part = reader()
ngx.say("read 3: ", "[", line, "]")
}
}
Output:
read 1: [-]
read 2: [--ab]
read 3: [--c]
After reading code, it seems that when some part of boundary pattern is consumed by other reading calls, the dfa doesn't reset state, so once find boundary pattern is not satisfy and copy data from cp->pattern will cause this problem (ngx_http_lua_socket_read_until->ngx_http_lua_socket_add_pending_data).
Since docs has mentioned that The iterator function can be called multiple times and can be mixed safely with other cosocket method calls or other iterator function calls., whether mixed call receiveuntil with receive is valid and the output is expected. Thanks for reply :).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the mixed receiveuntil and receive calls with the nginx configuration in the issue, then inspect ngx_http_lua_socket_read_until and ngx_http_lua_socket_add_pending_data. Compare the observed output with the documented promise that iterator calls can be mixed safely; done means the behavior is clarified and, if incorrect, corrected with coverage for this boundary-pattern case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, lua
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100