liquidsoap icon indicating copy to clipboard operation
liquidsoap copied to clipboard

Cleanup `Request.is_ready` logic

Open toots opened this issue 2 years ago • 0 comments

Request.is_ready semantics is unclear and buggy. See: https://github.com/savonet/liquidsoap/runs/5801028774?check_suite_focus=true

This is due to a couple of facts:

  • We are using the request's data to determine if it is ready. This should be a state
  • We have overloaded requests from originally representing a decodable media file to representing any downloaded file
  • Hence, the logic for is_ready says:
let is_ready t =
  t.indicators <> []
  && Sys.file_exists (peek_indicator t).string
  && (t.decoder <> None || t.ctype = None)

The (t.decoder <> None || t.ctype = None) condition is here to validate requests that are not media files (t.ctype = None). However, if a request represents a local file (Sys.file_exists (peek_indicator t).string = true) then it will always be considered ready.

Proposed solution:

  • Use a clear state for request resolution and implement it as a state machine.
  • Get rid of requests as an API to download files. We now support proper file downloading via http.get streaming requests and file.write callbacks.

toots avatar Apr 03 '22 16:04 toots