user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 4/3] httpd/async: do not needlessly weaken
  2016-05-27  6:17  7% ` [PATCH 1/3] httpd/async: prevent circular reference Eric Wong
@ 2016-05-27  7:32  6%   ` Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2016-05-27  7:32 UTC (permalink / raw)
  To: meta

The restart_read callback has no chance of circular reference,
and weakening $self before we create it can cause $self to
be undefined inside the callback (seen during stress testing).

Fixes: 395406118cb2 ("httpd/async: prevent circular reference")
---
 lib/PublicInbox/HTTPD/Async.pm | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm
index b00e637..add07ce 100644
--- a/lib/PublicInbox/HTTPD/Async.pm
+++ b/lib/PublicInbox/HTTPD/Async.pm
@@ -24,14 +24,19 @@ sub new {
 	$self;
 }
 
+sub restart_read_cb ($) {
+	my ($self) = @_;
+	sub { $self->watch_read(1) }
+}
+
 sub async_pass {
 	my ($self, $io, $fh, $bref) = @_;
 	# In case the client HTTP connection ($io) dies, it
 	# will automatically close this ($self) object.
 	$io->{forward} = $self;
 	$fh->write($$bref);
+	my $restart_read = restart_read_cb($self);
 	weaken($self);
-	my $restart_read = sub { $self->watch_read(1) };
 	$self->{cb} = sub {
 		my $r = sysread($self->{sock}, $$bref, 8192);
 		if ($r) {

^ permalink raw reply related	[relevance 6%]

* [PATCH 1/3] httpd/async: prevent circular reference
  2016-05-27  6:17  6% [PATCH 0/3] http: another round EPIPE fixes Eric Wong
@ 2016-05-27  6:17  7% ` Eric Wong
  2016-05-27  7:32  6%   ` [PATCH 4/3] httpd/async: do not needlessly weaken Eric Wong
  0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2016-05-27  6:17 UTC (permalink / raw)
  To: meta

We must avoid circular references which can cause leaks in
long-running processes.  This callback is dangerous since
it may never be called to properly terminate everything.
---
 lib/PublicInbox/HTTPD/Async.pm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm
index 47ba27d..b00e637 100644
--- a/lib/PublicInbox/HTTPD/Async.pm
+++ b/lib/PublicInbox/HTTPD/Async.pm
@@ -10,6 +10,7 @@ use strict;
 use warnings;
 use base qw(Danga::Socket);
 use fields qw(cb cleanup);
+use Scalar::Util qw(weaken);
 require PublicInbox::EvCleanup;
 
 sub new {
@@ -25,11 +26,12 @@ sub new {
 
 sub async_pass {
 	my ($self, $io, $fh, $bref) = @_;
-	my $restart_read = sub { $self->watch_read(1) };
 	# In case the client HTTP connection ($io) dies, it
 	# will automatically close this ($self) object.
 	$io->{forward} = $self;
 	$fh->write($$bref);
+	weaken($self);
+	my $restart_read = sub { $self->watch_read(1) };
 	$self->{cb} = sub {
 		my $r = sysread($self->{sock}, $$bref, 8192);
 		if ($r) {

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/3] http: another round EPIPE fixes
@ 2016-05-27  6:17  6% Eric Wong
  2016-05-27  6:17  7% ` [PATCH 1/3] httpd/async: prevent circular reference Eric Wong
  0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2016-05-27  6:17 UTC (permalink / raw)
  To: meta

Hopefully this is end of resource leaks on prematurely aborted
client connections.

Eric Wong (3):
      httpd/async: prevent circular reference
      http: avoid circular reference for getline responses
      git-http-backend: fix aborts for generic PSGI clone

 lib/PublicInbox/GetlineBody.pm    | 31 +++++++++++++++++++++++++++
 lib/PublicInbox/GitHTTPBackend.pm | 13 ++++-------
 lib/PublicInbox/HTTP.pm           | 45 ++++++++++++++++++++++++---------------
 lib/PublicInbox/HTTPD/Async.pm    |  4 +++-
 4 files changed, 66 insertions(+), 27 deletions(-)


^ permalink raw reply	[relevance 6%]

Results 1-3 of 3 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-05-27  6:17  6% [PATCH 0/3] http: another round EPIPE fixes Eric Wong
2016-05-27  6:17  7% ` [PATCH 1/3] httpd/async: prevent circular reference Eric Wong
2016-05-27  7:32  6%   ` [PATCH 4/3] httpd/async: do not needlessly weaken Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).