luckyframework / lucky

A full-featured Crystal web framework that catches bugs for you, runs incredibly fast, and helps you write code that lasts.
https://luckyframework.org
MIT License
2.57k stars 156 forks source link

IO::Error Headers already sent #1777

Open jwoertink opened 1 year ago

jwoertink commented 1 year ago

If a bug happens when calling response.print(body) from the TextResponse, then the ErrorHandler will try to do the same thing. This causes this error

  IO::Error 

     Headers already sent

    Backtrace 

     /usr/share/crystal/src/gc/boehm.cr:129:5 in 'print'
     /usr/share/crystal/src/gc/boehm.cr:129:5 in 'call_error_action'
     lib/lucky/src/lucky/error_handler.cr:16:5 in 'call'
     /usr/share/crystal/src/http/server/request_processor.cr:51:11 in 'process'
     /usr/share/crystal/src/http/server.cr:500:5 in '->'
     /usr/share/crystal/src/fiber.cr:146:11 in 'run'
     ???

We may need to check and see if the response has been closed before having the error handler try to give a response.