* [PATCH 1/7] view: close possible race condition in thread view
2015-09-02 6:59 7% [PATCH 0/7] improved thread views and 404 reductions Eric Wong
@ 2015-09-02 6:59 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2015-09-02 6:59 UTC (permalink / raw)
To: meta
It's possible that the Xapian index and git HEAD can be out-of-sync
and a message which existed when we did the search is no longer
accessible by the time we get to rendering it.
---
lib/PublicInbox/View.pm | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 6aa199e..1eb12a9 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -144,7 +144,7 @@ sub emit_thread_html {
my $msgs = load_results($res);
my $nr = scalar @$msgs;
return missing_thread($cb) if $nr == 0;
- my $fh = $cb->([200,['Content-Type'=>'text/html; charset=UTF-8']]);
+ my $orig_cb = $cb;
my $th = thread_results($msgs);
my $state = {
ctx => $ctx,
@@ -155,18 +155,23 @@ sub emit_thread_html {
{
require PublicInbox::GitCatFile;
my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
- thread_entry($fh, $git, $state, $_, 0) for $th->rootset;
+ thread_entry(\$cb, $git, $state, $_, 0) for $th->rootset;
}
Email::Address->purge_cache;
+
+ # there could be a race due to a message being deleted in git
+ # but still being in the Xapian index:
+ return missing_thread($cb) if ($orig_cb eq $cb);
+
my $final_anchor = $state->{anchor_idx};
my $next = "<a\nid=\"s$final_anchor\">";
$next .= $final_anchor == 1 ? 'only message in' : 'end of';
$next .= " thread</a>, back to <a\nhref=\"../../\">index</a>\n";
$next .= "download thread: <a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
$next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>\n\n";
- $fh->write("<hr />" . PRE_WRAP . $next . $foot .
+ $cb->write("<hr />" . PRE_WRAP . $next . $foot .
"</pre></body></html>");
- $fh->close;
+ $cb->close;
}
sub index_walk {
@@ -536,14 +541,16 @@ sub anchor_for {
}
sub thread_html_head {
- my ($mime) = @_;
+ my ($cb, $mime) = @_;
+ $$cb = $$cb->([200, ['Content-Type'=> 'text/html; charset=UTF-8']]);
+
my $s = PublicInbox::Hval->new_oneline($mime->header('Subject'));
$s = $s->as_html;
- "<html><head><title>$s</title></head><body>";
+ $$cb->write("<html><head><title>$s</title></head><body>");
}
sub thread_entry {
- my ($fh, $git, $state, $node, $level) = @_;
+ my ($cb, $git, $state, $node, $level) = @_;
return unless $node;
if (my $mime = $node->message) {
@@ -552,13 +559,13 @@ sub thread_entry {
$mime = eval { Email::MIME->new($git->cat_file("HEAD:$path")) };
if ($mime) {
if ($state->{anchor_idx} == 0) {
- $fh->write(thread_html_head($mime));
+ thread_html_head($cb, $mime);
}
- index_entry($fh, $mime, $level, $state);
+ index_entry($$cb, $mime, $level, $state);
}
}
- thread_entry($fh, $git, $state, $node->child, $level + 1);
- thread_entry($fh, $git, $state, $node->next, $level);
+ thread_entry($cb, $git, $state, $node->child, $level + 1);
+ thread_entry($cb, $git, $state, $node->next, $level);
}
sub load_results {
--
EW
^ permalink raw reply related [relevance 7%]
* [PATCH 0/7] improved thread views and 404 reductions
@ 2015-09-02 6:59 7% Eric Wong
2015-09-02 6:59 7% ` [PATCH 1/7] view: close possible race condition in thread view Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2015-09-02 6:59 UTC (permalink / raw)
To: meta
The thread HTML view may now be flat (chronological, newest
first) to make active threads easier-to-follow. We also make
unknown Message-IDs more usable by avoiding running SHA-1
on them.
The Message-ID finder is also handy for cross posts
and can probably link to multiple, external sources such as
mid.gmane.org and other places.
Eric Wong (7):
view: close possible race condition in thread view
view: optional flat view for recent messages
view: account for missing In-Reply-To header
view: simplify parent anchoring code
view: pre-anchor entries for flat view
view: avoid links to unknown compressed Message-IDs
implement external Message-ID finder
lib/PublicInbox/ExtMsg.pm | 92 ++++++++++++++++++++++++
lib/PublicInbox/Hval.pm | 4 +-
lib/PublicInbox/View.pm | 180 ++++++++++++++++++++++++++++++----------------
lib/PublicInbox/WWW.pm | 18 +++--
public-inbox.cgi | 1 +
5 files changed, 226 insertions(+), 69 deletions(-)
^ permalink raw reply [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-09-02 6:59 7% [PATCH 0/7] improved thread views and 404 reductions Eric Wong
2015-09-02 6:59 7% ` [PATCH 1/7] view: close possible race condition in thread view 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).