| 241 | ) |
| 242 | |
| 243 | def _validate_response(self, response): |
| 244 | try: |
| 245 | response = json.loads(response.read()) |
| 246 | error = response.get("error") |
| 247 | if error: |
| 248 | log.warning("Executor process: error response", command=self.command, error=error) |
| 249 | return False |
| 250 | assert response["jsonrpc"] == "2.0", "invalid jsonrpc version" |
| 251 | assert "id" in response, "no id in jsonrpc response" |
| 252 | result = response["result"] |
| 253 | if self.result_validator: |
| 254 | result_valid, reason = self.result_validator(result) |
| 255 | if not result_valid: |
| 256 | log.warning( |
| 257 | "Executor process: invalid response", |
| 258 | command=self.command, |
| 259 | result=result, |
| 260 | reason=reason, |
| 261 | ) |
| 262 | return False |
| 263 | except (AssertionError, KeyError, UnicodeDecodeError, JSONDecodeError) as ex: |
| 264 | log.warning("Executor process: invalid response", command=self.command, error=ex) |
| 265 | return False |
| 266 | return True |
| 267 | |
| 268 | def stop(self): |
| 269 | log.debug("Executor process: stopping process", command=self.command) |