Skip to content

🐛 [Bug]: can't close stream after sending via c.SendStream #3302

@KernelDeimos

Description

@KernelDeimos

Bug Description

I have an implementer of io.ReadCloser. I wish to stream the contents from this reader to the client and then close the reader after this is done. However. c.SendStream doesn't block or provide any way for me to know when the contents are done streaming, so this is actually impossible.

I had just migrated all my code from Gin because something in Gin turned out to be impossible, so this subsequent blocker definitely sucks.
I was able to get it working

defer myReadCloser.Close()
_, err = io.Copy(c.Response().BodyWriter(), myReadCloser)
if err != nil {
  return err
}

This was definitely very counterintuitive so I will leave this issue open (UX issues are still issues, right?). I also want to say thanks to the maintainers - the migration from Gin to Fiber was a little rough, but it has already allowed me to do two things that Gin wasn't capable of.

How to Reproduce

described in bug description

Expected Behavior

described in bug description

Fiber Version

v2.52.6

Code Snippet (optional)

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions