raku-community-modules / HTTP-Server-Async

Raku HTTP::Server::Async
Artistic License 2.0
18 stars 15 forks source link

Crashes a few seconds after a handling a request #24

Closed jkramer closed 7 years ago

jkramer commented 8 years ago

A couple of seconds after handling a request the server crashes with "Unhandled exception: cannot close a closed socket". This only happens if there's a break with no further requests after the last one. As long as requests come in frequently (tested with 1s intervals) it keeps running, so I suppose the problem is somewhere in the timeout/connection cleanup method: https://github.com/tony-o/perl6-http-server-async/blob/master/lib/HTTP/Server/Async.pm6#L30

tony-o commented 8 years ago

This should be resolved now, the problem was with the way moarvm was handling cross thread communication - there isn't much to do about it from the H:S:A perspective. There are still open RTs about the issue too, though, so it could still be a problem in the future.

dataf3l commented 8 years ago

I had the same problem, maybe:

Felipes-MacBook-Pro:backend2 a$ cat async.p6 use HTTP::Server::Async;

my $s = HTTP::Server::Async.new;

$s.handler(sub ($request, $response) { say $request.^methods; say $response.^methods;

$response.headers<Content-Type> = 'text/plain';

$response.status = 200; $response.write("Hello "); $response.close("world!"); #keeps a promise in the response and ends the server handler processing });

$s.listen(True); Felipes-MacBook-Pro:backend2 a$

Felipes-MacBook-Pro:backend2 a$ perl6 async.p6 (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) broken pipe in method flush at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/26F8AF8314B9D7E708012351E6E878218977B9AA (HTTP::Server::Async::Response) line 40 in method close at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/26F8AF8314B9D7E708012351E6E878218977B9AA (HTTP::Server::Async::Response) line 67 in sub at async.p6 line 12 in block at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/8146A2B9943C1F0852C1FD9FDB78BA26EC3248F7 (HTTP::Server::Async) line 101 in block at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/8146A2B9943C1F0852C1FD9FDB78BA26EC3248F7 (HTTP::Server::Async) line 94

(header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) broken pipe in method flush at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/26F8AF8314B9D7E708012351E6E878218977B9AA (HTTP::Server::Async::Response) line 40 in method close at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/26F8AF8314B9D7E708012351E6E878218977B9AA (HTTP::Server::Async::Response) line 67 in sub at async.p6 line 12 in block at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/8146A2B9943C1F0852C1FD9FDB78BA26EC3248F7 (HTTP::Server::Async) line 101 in block at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/8146A2B9943C1F0852C1FD9FDB78BA26EC3248F7 (HTTP::Server::Async) line 94

(header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) broken pipe in method flush at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/26F8AF8314B9D7E708012351E6E878218977B9AA (HTTP::Server::Async::Response) line 40 in method close at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/26F8AF8314B9D7E708012351E6E878218977B9AA (HTTP::Server::Async::Response) line 67 in sub at async.p6 line 12 in block at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/8146A2B9943C1F0852C1FD9FDB78BA26EC3248F7 (HTTP::Server::Async) line 101 in block at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/8146A2B9943C1F0852C1FD9FDB78BA26EC3248F7 (HTTP::Server::Async) line 94

(header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) broken pipe in method flush at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/26F8AF8314B9D7E708012351E6E878218977B9AA (HTTP::Server::Async::Response) line 40 in method close at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/26F8AF8314B9D7E708012351E6E878218977B9AA (HTTP::Server::Async::Response) line 67 in sub at async.p6 line 12 in block at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/8146A2B9943C1F0852C1FD9FDB78BA26EC3248F7 (HTTP::Server::Async) line 101 in block at /usr/local/Cellar/rakudo-star/2016.10/share/perl6/site/sources/8146A2B9943C1F0852C1FD9FDB78BA26EC3248F7 (HTTP::Server::Async) line 94

(header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) (header response complete connection method uri version data params headers) (unbuffer rebuffer flush write close status headers connection statuscodes) Segmentation fault: 11 Felipes-MacBook-Pro:backend2 a$

which meant I can't use this piece of software in production, I'm using HTTP::Server::Tiny for now, until this is resolved, sorry guys, this is a deal breaker for me.

tony-o commented 7 years ago

I think this is a separate issue. I'm looking into this problem but the segfault is usually outside of my control and has to do with the way pointer passing happens in moar -

tony-o commented 7 years ago

@dataf3l what's the perl6 -v? Looks like 2016.10, can you try updating please? There have been a couple of updates to moar that should fix that segfault issue.

dataf3l commented 7 years ago

This is Rakudo version 2016.10 built on MoarVM version 2016.10 implementing Perl 6.c.

Should I be using something different?

On Wed, Nov 9, 2016 at 8:07 PM, tony-o notifications@github.com wrote:

@dataf3l https://github.com/dataf3l what's the perl6 -v? Looks like 2016.10, can you try updating please? There have been a couple of updates to moar that should fix that segfault issue.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tony-o/perl6-http-server-async/issues/24#issuecomment-259573844, or mute the thread https://github.com/notifications/unsubscribe-auth/ADXWcODuA_Y3kZRfVNRj4P1NrvgWSPVKks5q8m43gaJpZM4JYHns .

tony-o commented 7 years ago

You might try reinstalling the module now - I've commented out the line causing the issue until I can figure out a permanent fix

Sent from my iPhone

On Nov 10, 2016, at 9:07 AM, felipe notifications@github.com<mailto:notifications@github.com> wrote:

This is Rakudo version 2016.10 built on MoarVM version 2016.10 implementing Perl 6.c.

Should I be using something different?

On Wed, Nov 9, 2016 at 8:07 PM, tony-o notifications@github.com<mailto:notifications@github.com> wrote:

@dataf3l https://github.com/dataf3l what's the perl6 -v? Looks like 2016.10, can you try updating please? There have been a couple of updates to moar that should fix that segfault issue.

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tony-o/perl6-http-server-async/issues/24#issuecomment-259573844, or mute the thread https://github.com/notifications/unsubscribe-auth/ADXWcODuA_Y3kZRfVNRj4P1NrvgWSPVKks5q8m43gaJpZM4JYHns .

You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/tony-o/perl6-http-server-async/issues/24#issuecomment-259748046, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AB75kKskukS5Hppf8HEkZQewA8l06Tkcks5q809OgaJpZM4JYHns.

tony-o commented 7 years ago

@dataf3l can you confirm this is still an issue after doing the following:

  1. clone repo
  2. alter lib/HTTP/Server/Async.pm6 and remove the # from line 39.
  3. zef install .
  4. run whatever your test is that's causing the issue -
nicqrocks commented 7 years ago

I've noticed that this happens without uncommenting line 39 and using the ab.pl6 file included in the repo. Still gives the same error: Unhandled exception: cannot close a closed socket.

Steps to reproduce:

  1. Clone repo
  2. cd perl6-http-server-async
  3. perl6 ab.pl6
  4. Open web browser (Firefox in my case) to http://localhost:1666
  5. Wait ~7 seconds

HTTP::Server::Async v0.1.3

This is Rakudo version 2017.01-53-gaecbb3e built on MoarVM version 2017.01-13-g4aab506 implementing Perl 6.c.

tony-o commented 7 years ago

@nicqrocks what OS?

nicqrocks commented 7 years ago

Linux Mint 17.3

On Wed, Feb 8, 2017, 11:27 AM tony-o notifications@github.com wrote:

@nicqrocks https://github.com/nicqrocks what OS?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tony-o/perl6-http-server-async/issues/24#issuecomment-278378225, or mute the thread https://github.com/notifications/unsubscribe-auth/AKDNk8qQB-yjndKg18t10nQ9ib95pGzWks5raezsgaJpZM4JYHns .

tony-o commented 7 years ago

@nicqrocks okay, I gave jnthn enough of a trace that he figured out where/what he needs to change in moar/core (not sure which) that we should be able to stop the segfault and this issue -

tony-o commented 7 years ago

@nicqrocks can you do zef update and then reinstall H:S:A? Please verify that it pulls down version 0.1.4

nicqrocks commented 7 years ago

@tony-o zef does not want to pull the newest version (still tries to grab 0.1.3) but I got the repo from git. When running ab.pl6 it no longer dies, but it hangs when running through the tests. I think this is due to the while (my $str = $client.recv) loop in 01_request.t (that is where the tests hang for me), but I cannot tell for sure. Thank you very much for your help with this. 😄

Edit: Figured out why it hangs. See PR #29

tony-o commented 7 years ago

Is it okay to close now with PR#29 @nicqrocks ?

nicqrocks commented 7 years ago

Yep, I have not had any trouble with it since the fix. Thank you very much!

On Fri, Feb 17, 2017, 1:33 PM tony-o notifications@github.com wrote:

Is it okay to close now with PR#29 @nicqrocks https://github.com/nicqrocks ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/perl6/perl6-http-server-async/issues/24#issuecomment-280730067, or mute the thread https://github.com/notifications/unsubscribe-auth/AKDNk90tIDGB5oeF3jyIe65zP_6Ivb3xks5rdegUgaJpZM4JYHns .