Actions
Task #6120
closedTask #6116: EPIC: Speed up the stats updater daemon (scripts/workflow/update_stats.sh)
Fix releaseToken: response body read twice, so IIKO sessions leak
Status:
Resolved
Priority:
Urgent
Assignee:
-
Start date:
08/26/2026
Due date:
% Done:
100%
Estimated time:
Description
Problem¶
IikoAuthTokensFetchingService.releaseToken consumes the OkHttp response body twice:
64: if (response.body?.string()!!.contains("Connection released")) { ... }
68: if (response.body?.string()!!.contains("Token is expired or invalid")) { ... }
ResponseBody.string() reads and closes the stream. The second call at line 68 therefore throws on an already-consumed body, which means:
- the "Token is expired or invalid" branch is dead code — it can never be reached;
- any logout response that is not exactly "Connection released" ends in an exception (either the
IllegalStateExceptionfrom the consumed body, or the explicitthrow Exception("Не удалось освободить токен")at the end); - the token row is left
isActive = truein our DB while the IIKO-side session may or may not be closed.
Because fetchOlapData calls releaseToken in the middle of its happy path (line 56, after the data is already in hand), a throw here discards a successful OLAP result and burns a session. With one session opened per request (see the session-reuse task) this compounds directly into the concurrency-limit symptom.
Also note the two response.close() calls in fetchOlapData (lines 50 and 54) — the second is redundant.
Proposed change¶
- Read the body once into a local
val, branch on that. - Mark the token inactive locally on any terminal outcome, including a failed logout — a token we can no longer use is not active regardless of what IIKO said.
- Do not let a logout failure propagate out of a successful data fetch; log it.
Acceptance¶
-
releaseTokennever reads the body more than once. - A non-"Connection released" logout response no longer throws out of
fetchOlapData.
Actions