Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lucky::TextResponse#print raises exception if the client has gone away. #1608

Closed
BrucePerens opened this issue Nov 4, 2021 · 2 comments · Fixed by #1609
Closed

Lucky::TextResponse#print raises exception if the client has gone away. #1608

BrucePerens opened this issue Nov 4, 2021 · 2 comments · Fixed by #1609
Labels

Comments

@BrucePerens
Copy link

context.response.print body

This raises IO::Error if the client has gone away and there is no longer a valid socket to write to. It should catch IO::Error and simply log that the client went away before the response could be sent. Perhaps the error should be handled in HTTP::Server rather than Lucky. The backtrace is:

▸ Rendered Page::Search::Product::Result
 ▸  IO::Error 

     Error writing to socket: Broken pipe

    Backtrace 

/usr/share/crystal/src/io/evented.cr:82:13 in 'unbuffered_write'
     /usr/share/crystal/src/io/buffered.cr:152:14 in 'write'
     /usr/share/crystal/src/http/server/response.cr:223:11 in 'unbuffered_write'
     /usr/share/crystal/src/io/buffered.cr:152:14 in 'write'
     /usr/share/crystal/src/http/server/response.cr:86:7 in 'write'
     /usr/share/crystal/src/io/memory.cr:412:5 in 'to_s'
     /usr/share/crystal/src/io.cr:174:5 in '<<'
     /usr/share/crystal/src/io.cr:188:5 in 'print'
     lib/lucky/src/lucky/text_response.cr:32:5 in 'print'
     lib/lucky/src/lucky/renderable.cr:145:5 in 'handle_response'
     lib/lucky/src/lucky/renderable.cr:140:5 in 'perform_action'
     lib/lucky/src/lucky/route_handler.cr:10:7 in 'call'
     /usr/share/crystal/src/http/server/request_processor.cr:51:11 in 'process'
     /usr/share/crystal/src/http/server.cr:515:5 in 'handle_client'
     /usr/share/crystal/src/http/server.cr:468:13 in '->'
     /usr/share/crystal/src/primitives.cr:266:3 in 'run'
     /usr/share/crystal/src/fiber.cr:92:34 in '->'
@jwoertink
Copy link
Member

I've been trying to find this error for a long time! crystal-lang/crystal#9065 Thanks for tracking it down!

I'm not sure where the actual error should be fixed, but I guess if we just catch IO::Error, maybe that's good enough for now? What do other frameworks do in this situation?

@BrucePerens
Copy link
Author

Tear down the response so that there are no further writes. HTTP::Server should get rid of the file descriptor for that accept on its own.

jwoertink added a commit that referenced this issue Nov 12, 2021
…ing to the response then just log the error. Generally there's not much we can do at this point. Fixes #1608
jwoertink added a commit that referenced this issue Nov 15, 2021
…ing to the response then just log the error. Generally there's not much we can do at this point. Fixes #1608 (#1609)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants