Openresty websocket: payload too big


We use lua-resty-websocket to create websocket server:

https://github.com/openresty/lua-resty-websocket

					local bytes, err =wb:send_binary(content)
					
					if err then
						ngx.log(ngx.ERR, 'err:'..err)
					end

And we see in log file:

2022/04/26 08:14:40 [error] 525690#525690: *1 [lua] content_by_lua(default:2538):60: err:payload too big, client: 14.111.19.65, server: _, request: "GET /test/ws HTTP/1.1", host: "5.111.72.222"

Solution: chunk data then send each chunk:

	function splitByChunk(text, chunkSize)
		local s = {}
		chunkSize = chunkSize or 2048
		for i=1, #text, chunkSize do
			s[#s+1] = text:sub(i,i+chunkSize - 1)
		end
		return s
	end

We use some value of chunkSize to determine the frame limitation size and we found this value is 1024*64-1 = 65535

				local st9 = splitByChunk(content,1024*32)
				for j1,j2 in pairs(st9) do				 
					local bytes, err = wb:send_binary(j2)
					
					if err then
						ngx.log(ngx.ERR, 'err:'..err)
					end
				
				end

Leave a Reply