swh-graph: "Cannot open client FIFO" when answering HEAD requests
The current implementation of HEAD requests works fine from the point of view of the client, but makes the Java backend fail with a traceback when trying to write the body of the answer (to the Py4J middleware, I think). Example follows:
Client:
$ curl --head http://0.0.0.0:5009/graph/leaves/swh:1:ori:44ae7491d67a6879a1fba30cadb189c60e34b877
HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked
Date: Tue, 12 Nov 2019 13:55:49 GMT
Server: Python/3.7 aiohttp/3.5.4
Server:
$ swh graph rpc-serve -g sample/big/compressed/swh-graph
INFO:root:using swh-graph JAR: /home/zack/dati/projects/sw-heritage/git/swh-environment/swh-graph/java/target/swh-graph-0.2.0.jar
Loading graph sample/big/compressed/swh-graph ...
Graph loaded.
======== Running on http://0.0.0.0:5009 ========
(Press CTRL+C to quit)
ERROR:root:
Traceback (most recent call last):
File "/home/zack/dati/projects/sw-heritage/git/swh-environment/swh-core/swh/core/api/asynchronous.py", line 56, in middleware_handler
return await handler(request)
File "/home/zack/dati/projects/sw-heritage/git/swh-environment/swh-graph/swh/graph/server/app.py", line 119, in simple_traversal
ttype, direction, edges, src_node
File "/home/zack/dati/projects/sw-heritage/git/swh-environment/swh-graph/swh/graph/backend.py", line 109, in simple_traversal
async for node_id in method(direction, edges_fmt, src):
File "/home/zack/dati/projects/sw-heritage/git/swh-environment/swh-graph/swh/graph/backend.py", line 208, in java_call_iterator
async for value in reader:
File "/home/zack/dati/projects/sw-heritage/git/swh-environment/swh-graph/swh/graph/backend.py", line 169, in read_node_ids
with (await asyncio.wait_for(open_thread, timeout=2)) as f:
File "/usr/lib/python3.7/asyncio/tasks.py", line 435, in wait_for
await waiter
concurrent.futures._base.CancelledError
ERROR:aiohttp.server:Unhandled exception
Traceback (most recent call last):
File "/home/zack/.virtualenvs/swh/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 447, in start
await resp.prepare(request)
File "/home/zack/.virtualenvs/swh/lib/python3.7/site-packages/aiohttp/web_response.py", line 353, in prepare
return await self._start(request)
File "/home/zack/.virtualenvs/swh/lib/python3.7/site-packages/aiohttp/web_response.py", line 667, in _start
return await super()._start(request)
File "/home/zack/.virtualenvs/swh/lib/python3.7/site-packages/aiohttp/web_response.py", line 410, in _start
await writer.write_headers(status_line, headers)
File "/home/zack/.virtualenvs/swh/lib/python3.7/site-packages/aiohttp/http_writer.py", line 112, in write_headers
self._write(buf)
File "/home/zack/.virtualenvs/swh/lib/python3.7/site-packages/aiohttp/http_writer.py", line 67, in _write
raise ConnectionResetError('Cannot write to closing transport')
ConnectionResetError: Cannot write to closing transport
ERROR:asyncio:Task exception was never retrieved
future: <Task finished coro=<JavaStreamProxy._HandlerWrapper.__getattr__.<locals>.java_call() done, defined at /home/zack/dati/projects/sw-heritage/git/swh-environment/swh-graph/swh/graph/backend.py:184> exception=Py4JJavaError('An error occurred while calling o1.leaves.\n', JavaObject id=o2)>
Traceback (most recent call last):
File "/home/zack/dati/projects/sw-heritage/git/swh-environment/swh-graph/swh/graph/backend.py", line 186, in java_call
await loop.run_in_executor(None, lambda: func(*args, **kwargs))
File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/zack/dati/projects/sw-heritage/git/swh-environment/swh-graph/swh/graph/backend.py", line 186, in <lambda>
await loop.run_in_executor(None, lambda: func(*args, **kwargs))
File "/home/zack/.virtualenvs/swh/lib/python3.7/site-packages/py4j/java_gateway.py", line 1286, in __call__
answer, self.gateway_client, self.target_id, self.name)
File "/home/zack/.virtualenvs/swh/lib/python3.7/site-packages/py4j/protocol.py", line 328, in get_return_value
format(target_id, ".", name), value)
py4j.protocol.Py4JJavaError: An error occurred while calling o1.leaves.
: java.lang.RuntimeException: Cannot open client FIFO: java.io.FileNotFoundException: /tmp/swh-graph-_e6bobe5/swh-graph.fifo (No such file or directory)
at org.softwareheritage.graph.Entry$QueryHandler.open(Entry.java:101)
at org.softwareheritage.graph.Entry$QueryHandler.leaves(Entry.java:114)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.base/java.lang.Thread.run(Thread.java:834)
Migrated from T2081 (view on Phabricator)