Skip to content

Commit

Permalink
jsonrpc.PARSE_ERROR
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Jan 15, 2025
1 parent ba883a2 commit 6fa2315
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions kong/clustering/rpc/socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ function _M:start()

local payload = decompress_payload(data)

if not payload then
local res, err = self:push_response(
new_error(nil, jsonrpc.PARSE_ERROR))
if not res then
return nil, err
end

goto continue
end

-- single rpc call
if not isarray(payload) then
local ok, err = self:process_rpc_msg(payload)
Expand Down
6 changes: 6 additions & 0 deletions spec/02-integration/18-hybrid_rpc/02-error_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ for _, strategy in helpers.each_strategy() do
helpers.pwait_until(function()
assert.logfile(name).has.line(
"[rpc] RPC failed, code: -32600, err: empty batch array", true)

assert.logfile(dp_logfile).has.line(
"[rpc] got batch RPC call: 1", true)
assert.logfile(name).has.line(
"[rpc] RPC failed, code: -32600, err: not a valid object", true)

assert.logfile(name).has.line(
"test #2 ok", true)
assert.logfile(name).has.no.line(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ function RpcErrorTestHandler:init_worker()

end, "clustering:jsonrpc", "connected")

-- if rpc is ready we will start to send raw msg
worker_events.register(function(capabilities_list)
local s = next(kong.rpc.clients[node_id])

-- send an empty array
local msg = setmetatable({}, cjson.array_mt)
assert(s:push_request({}))
assert(s:push_request(msg))

-- send a invalid msg
local msg = ({"invalid_request"})
assert(s:push_request(msg))

ngx.log(ngx.DEBUG, "test #2 ok")

Expand Down

0 comments on commit 6fa2315

Please sign in to comment.