From aac983c95d33f2fa86b909e9e0f7ff3b47f5d7b5 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 25 Jan 2020 16:31:41 +0000 Subject: timeout when parsing a socket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit if the socket doesn't send an email message, we would be stuck waiting for it to do so since a socket is not a pipe, we can't detect "the other end has finished talking" ☹ --- lib/MaildirIndexer/Parser.rakumod | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/MaildirIndexer/Parser.rakumod b/lib/MaildirIndexer/Parser.rakumod index d30ca86..c92fa22 100644 --- a/lib/MaildirIndexer/Parser.rakumod +++ b/lib/MaildirIndexer/Parser.rakumod @@ -86,7 +86,7 @@ multi parse-email(IO::Path:D $p, :$headers-only! --> MaildirIndexer::Email) is e return $result; } -multi parse-email(IO::Socket::Async:D $s --> MaildirIndexer::Email) is export { +multi parse-email(IO::Socket::Async:D $s, Int $timeout = 1 --> MaildirIndexer::Email) is export { my MaildirIndexer::Email $result; MaildirIndexer::LogTimelineSchema::Parse::Email::Socket.log: -> { my $string; @@ -99,6 +99,7 @@ multi parse-email(IO::Socket::Async:D $s --> MaildirIndexer::Email) is export { $result = parse-email($string) and done; QUIT { done }; } + whenever Promise.in($timeout) { done } } } return $result; -- cgit v1.2.3