Skip to content

Commit

Permalink
Make request IDs unique across clients (#4524)
Browse files Browse the repository at this point in the history
Changes the ID fields of the requests being sent to the kore RPC server.
Before they were just integers counting up the requests of each client,
but it is useful to be able to see in the logs which requests are coming
from which client, so this changes the IDs to be this same counter, but
prepended with `id()` of the client that is making the request.

---------

Co-authored-by: Tamás Tóth <[email protected]>
  • Loading branch information
nwatson22 and tothtamas28 authored Jul 17, 2024
1 parent c373e13 commit 2c95ae9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pyk/src/pyk/kore/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def __init__(self, bug_report_id: str | None = None, bug_report: BugReport | Non
self._bug_report_id = bug_report_id
self._bug_report = bug_report

def request(self, req: str, request_id: int, method_name: str) -> str:
def request(self, req: str, request_id: str, method_name: str) -> str:
base_name = self._bug_report_id if self._bug_report_id is not None else 'kore_rpc'
req_name = f'{base_name}/{id(self)}/{request_id:03}'
req_name = f'{base_name}/{id(self)}/{request_id}'
if self._bug_report:
bug_report_request = f'{req_name}_request.json'
self._bug_report.add_file_contents(req, Path(bug_report_request))
Expand Down Expand Up @@ -340,24 +340,24 @@ def close(self) -> None:
self._transport.close()

def request(self, method: str, **params: Any) -> dict[str, Any]:
old_id = self._req_id
req_id = f'{id(self)}-{self._req_id:03}'
self._req_id += 1

payload = {
'jsonrpc': self._JSON_RPC_VERSION,
'id': old_id,
'id': req_id,
'method': method,
'params': params,
}

req = json.dumps(payload)
resp = self._transport.request(req, old_id, method)
resp = self._transport.request(req, req_id, method)
if not resp:
raise RuntimeError('Empty response received')

data = json.loads(resp)
self._check(data)
assert data['id'] == old_id
assert data['id'] == req_id

return data['result']

Expand Down

0 comments on commit 2c95ae9

Please sign in to comment.