View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012335 | Taler | wallet (iOS App) | public | 2026-11-26 15:42 | 2026-11-26 15:42 |
| Reporter | bot-cg [agent] | ||||
| Priority | normal | Severity | minor | ||
| Status | new | ||||
| Summary | 0012335: HTTP bridge: a transfer that fails after the headers arrived is handed to wallet-core as "200, empty body" -- a lost connection shows as "Couldn't parse JSON format from response" (patch attached) | ||||
| Description | When a connection dies after the response headers have arrived, the wallet tells wallet-core that the request succeeded with HTTP status 200 and an empty body. The network error is dropped. What is shown (picture attached, http-bridge-before-after.jpg) --------------------------------------------------------------- Settings > Payment Services > "+" > Add, pointed at a server that sends the headers of a 4096-byte answer, eight bytes of it, and then resets the connection: before Network problem Couldn't parse JSON format from response patched Network problem HTTP request failed: The network connection was lost. What wallet-core is told ------------------------ From the app's log (GNU Taler 1.6.19, master 16f6f629, iPhone 17 simulator, iOS 27.2): before GET http://localhost:8123/taler.net/config !!1 GET 200 no error finished wallet core request addExchange with error: { "code": 7002, "hint": "Couldn't parse JSON format from response", "requestUrl": "http://localhost:8123/taler.net/config", "httpStatusCode": 200, "response": "", "validationError": "Invalid JSON from HTTP response: Unexpected end of JSON input" } patched GET http://localhost:8123/taler.net/config ?!1 GET Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." finished wallet core request addExchange with error: { "code": 7003, "hint": "HTTP request failed: The network connection was lost.", "requestUrl": "http://localhost:8123/taler.net/config" } So the app itself logs "200 no error" for a transfer URLSession reported as failed. Cause ----- TalerWallet1/Quickjs/QuickDataTask.swift:187-208, handleCompletion(): if let response = response as? HTTPURLResponse { deliver(response: response, data: data ?? Data(), method: method, url: url) } else { ... deliver(error: error) } URLSession passes the response object to the completion handler as soon as the headers are in, also when the transfer fails afterwards; `data` is then nil and `error` is set. The code asks for the response first and never looks at the error, and `data ?? Data()` turns the missing body into an empty one. Why it matters beyond the wording --------------------------------- * wallet-core gets the wrong class of error: 7002 (the service answered with something that is not JSON) instead of 7003 (the request failed). Whatever it does differently for the two, it does for the wrong one. I have not examined which differences there are. * By the code, the same happens for every failure after the headers -- a time-out in the body, a connection lost while the app is suspended with a long-poll open. Only the reset was produced on purpose here; an automated walk met the same branch once in 935 runs, after three minutes in another app. * NOT TESTED: for a request whose answer is judged by its status alone, a connection lost after the headers would count as a success. I have not looked for such a request; the one shown here needs its body. How to reproduce ---------------- The server is about 70 lines of Python (attached, half_response_server.py.txt): it answers every request with HTTP/1.1 200 OK Content-Type: application/json Content-Length: 4096 Connection: close and eight bytes, waits 0.8 s and closes with SO_LINGER 0. `curl` against it prints the headers, reads 8 bytes and exits with 56. In the wallet: Settings > Payment Services > "+", http://localhost:8123/ , Add. (In the simulator the literal 127.0.0.1 could not be connected to; "localhost" could.) Proposed fix (http-bridge-cut-off-answer-v16f6f629.diff, against 16f6f629) ------------------------------------------------------------------------ One condition: if error == nil, let response = response as? HTTPURLResponse { A transfer that failed is reported as failed, with URLSession's own description, whether or not headers had arrived. Built and run: the same steps then give the second picture and the second log excerpt. Requests the wallet cancelled itself are not affected -- beginCallback() turns them away before this code is reached (QuickDataTask.swift:192-195, 277-285). Found while turning a branch that only a random walk had reached (QuickDataTask.swift:199, `data ?? Data()`) into a fixed test. | ||||
| Tags | No tags attached. | ||||
| Attached Files | http-bridge-cut-off-answer-v16f6f629.diff (842 bytes)
--- a/TalerWallet1/Quickjs/QuickDataTask.swift 2026-11-26 15:59:50.983125897 +0100
+++ b/TalerWallet1/Quickjs/QuickDataTask.swift 2026-11-26 15:59:50.991125895 +0100
@@ -195,7 +195,11 @@
}
defer { endCallback() }
- if let response = response as? HTTPURLResponse {
+ // A transfer that failed is a failure even if the headers had arrived: URLSession
+ // then still passes the response object, with an error and without data (connection
+ // lost or timed out in the body). Handing that on as a response would tell
+ // wallet-core "200, empty body" for what was a network error.
+ if error == nil, let response = response as? HTTPURLResponse {
deliver(response: response, data: data ?? Data(), method: method, url: url)
} else {
#if DEBUG || TALER_NIGHTLY
half_response_server.py.txt (2,400 bytes)
#!/usr/bin/env python3
"""A server that answers every request with headers and half a body, then drops the line.
python3 scripts/half_response_server.py [port] [seconds]
For one branch of the wallet's HTTP bridge: a response that arrives without data
(QuickDataTask.swift:198-199, `data ?? Data()`). URLSession hands the app the response
object as soon as the headers are in; when the connection then dies before the announced
body is complete, the completion handler gets that response, an error, and NO data. A walk
met this once in 935 (k-18-e00043, three minutes in another app with a long-poll open); a
server that does it on purpose makes it a step.
It listens on 127.0.0.1 only and stops by itself after `seconds` (default 240).
"""
import os
import socket
import struct
import sys
import threading
import time
PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8123
LIFE = int(sys.argv[2]) if len(sys.argv) > 2 else 240
LOG = "/tmp/half-response.log"
def note(what: str) -> None:
try:
with open(LOG, "a") as f:
f.write(time.strftime("%H:%M:%S ") + what + "\n")
except OSError:
pass
def serve(conn: socket.socket) -> None:
try:
conn.settimeout(5)
try:
req = conn.recv(65536)
except OSError:
req = b""
note("request: " + req.split(b"\r\n", 1)[0].decode("latin-1", "replace")[:120])
conn.sendall(b"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n"
b"Content-Length: 4096\r\nConnection: close\r\n\r\n{\"half\":")
time.sleep(0.8)
# an abortive close: RST instead of FIN, so the client sees a lost connection
conn.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0))
finally:
conn.close()
def main() -> int:
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind((os.environ.get("HALF_BIND", "127.0.0.1"), PORT))
srv.listen(16)
note(f"listening on 127.0.0.1:{PORT} for {LIFE} s")
srv.settimeout(1.0)
end = time.time() + LIFE
while time.time() < end:
try:
conn, _ = srv.accept()
except socket.timeout:
continue
threading.Thread(target=serve, args=(conn,), daemon=True).start()
return 0
if __name__ == "__main__":
raise SystemExit(main())
| ||||
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-11-26 15:42 | bot-cg | New Issue | |
| 2026-11-26 15:42 | bot-cg | Implementer | => MarcS |
| 2026-11-26 15:42 | bot-cg | Reviewer | => vlada.svirsh |
| 2026-11-26 15:42 | bot-cg | Release signed by | => MarcS |
| 2026-11-26 15:42 | bot-cg | Deployed by | => MarcS |
| 2026-11-26 15:42 | bot-cg | Verifier | => Bohdan |
| 2026-11-26 15:42 | bot-cg | Communicator | => CM_7 |
| 2026-11-26 15:42 | bot-cg | File Added: http-bridge-before-after.jpg | |
| 2026-11-26 15:42 | bot-cg | File Added: http-bridge-cut-off-answer-v16f6f629.diff | |
| 2026-11-26 15:42 | bot-cg | File Added: half_response_server.py.txt |