fix(rest): download unknown cid (#48)
Downloading a CID that is unknown to the network would wait for the blockexchange to try to get the data. However, a subsequent API call, eg upload for that CID, or a blockexchange timeout would cause the dagger node to crash, due to an attempt to complete a future that had already been completed. We were able to narrow this down to an attempt to call `resp.finish()` when the download block had already returned an `RestApiResponse` (and never sent any chunks to the response from the libp2p stream). Change the HTTP response code for an unknown cid from 400 to 404. Fix spelling mistake “cunk”. Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com> Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
This commit is contained in:
parent
5f48de6a44
commit
ec66e42e73
|
@ -111,7 +111,7 @@ proc initRestApi*(node: DaggerNodeRef): RestRouter =
|
||||||
if (
|
if (
|
||||||
let retr = await node.retrieve(stream, id.get());
|
let retr = await node.retrieve(stream, id.get());
|
||||||
retr.isErr):
|
retr.isErr):
|
||||||
return RestApiResponse.error(Http400, retr.error.msg)
|
return RestApiResponse.error(Http404, retr.error.msg)
|
||||||
|
|
||||||
await resp.prepareChunked()
|
await resp.prepareChunked()
|
||||||
while not stream.atEof:
|
while not stream.atEof:
|
||||||
|
@ -124,15 +124,15 @@ proc initRestApi*(node: DaggerNodeRef): RestRouter =
|
||||||
break
|
break
|
||||||
|
|
||||||
bytes += buff.len
|
bytes += buff.len
|
||||||
trace "Sending cunk", size = buff.len
|
trace "Sending chunk", size = buff.len
|
||||||
await resp.sendChunk(addr buff[0], buff.len)
|
await resp.sendChunk(addr buff[0], buff.len)
|
||||||
|
await resp.finish()
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
trace "Excepting streaming blocks", exc = exc.msg
|
trace "Excepting streaming blocks", exc = exc.msg
|
||||||
return RestApiResponse.error(Http500)
|
return RestApiResponse.error(Http500)
|
||||||
finally:
|
finally:
|
||||||
trace "Sent bytes", cid = id.get(), bytes
|
trace "Sent bytes", cid = id.get(), bytes
|
||||||
await stream.close()
|
await stream.close()
|
||||||
await resp.finish()
|
|
||||||
|
|
||||||
router.rawApi(
|
router.rawApi(
|
||||||
MethodPost,
|
MethodPost,
|
||||||
|
|
Loading…
Reference in New Issue