From 2c95ae9a4949937c54090abead4e0b235ab413f6 Mon Sep 17 00:00:00 2001 From: Noah Watson <107630091+nwatson22@users.noreply.github.com> Date: Wed, 17 Jul 2024 10:27:47 -0500 Subject: [PATCH] Make request IDs unique across clients (#4524) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pyk/src/pyk/kore/rpc.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pyk/src/pyk/kore/rpc.py b/pyk/src/pyk/kore/rpc.py index 379042aca1c..99bb41cac0a 100644 --- a/pyk/src/pyk/kore/rpc.py +++ b/pyk/src/pyk/kore/rpc.py @@ -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)) @@ -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']