Skip to content

Conversation

@yuji-hatakeyama
Copy link
Contributor

@yuji-hatakeyama yuji-hatakeyama commented Sep 24, 2025

(日本語で失礼します。英語で作成したほうが良ければご連絡ください)

概要

通常、HTTP レスポンスボディの受信中にクライアント側でタイムアウトした場合は、
Cannot read content body: timeout ... というエラーを返す挙動になっています。

? "Cannot read content body: " . _strerror_or_timeout()

しかし、レスポンスヘッダに Content-Length がない場合に限って、
タイムアウト時でもその時点まで受信できたボディを正常扱いで返してしまう挙動がありました
(結果としてボディが途中で切れてしまう)。

last if ! defined($res_content_length);

この挙動を修正し、Content-Length がない場合でもボディ受信中のタイムアウトはエラーを返すようにしました。

経緯

あるスクリプトで JSON を返す API に対して以下のようなリクエストを実行していましたが、
まれに JSON のデコードに失敗しました($res->is_success を確認後にもかかわらず)。

my $furl = Furl->new(timeout => 60);
my $res = $furl->get($url);
unless ($res->is_success) {
    die "Failed to get";
}
my $data = JSON::XS::decode_json $res->content;

失敗時はスクリプトの実行時間がタイムアウト値と同程度になっていることが多く(通常は 2〜3秒)、
タイムアウトを 60 秒から 1 秒へ下げると高確率で再現しました。

このことから、「クライアント側でのタイムアウトが発生したときに $res->is_success になるが、レスポンスが途中で切れてしまう」というパターンがあることに気付きました。

一次対応として JSON デコード失敗時にリトライしていますが、本修正により根本的に解消されます。
方針・実装内容のご確認をお願いいたします。

matrix:
perl-version:
- '5.14'
- '5.26'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perl:5.14 のimage では以下の問題が発生。

2025-09-23T14:12:53.8469117Z ##[command]/usr/bin/docker pull perl:5.14
2025-09-23T14:12:54.0843447Z 5.14: Pulling from library/perl
2025-09-23T14:12:54.0850220Z [DEPRECATION NOTICE] Docker Image Format v1 and Docker Image manifest version 2, schema 1 support is disabled by default and will be removed in an upcoming release. Suggest the author of docker.io/library/perl:5.14 to upgrade the image to the OCI Format or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/
2025-09-23T14:12:54.0960876Z ##[error]Docker pull failed with exit code 1

https://github.com/yuji-hatakeyama/Furl/actions/runs/17948982318/job/51042726049#step:2:29

Perl 5.22 の image でこの問題は解消したが、別の問題が発生。

2025-09-23T19:51:01.0459218Z ##[command]/usr/bin/docker exec  d2f4656322d911b45a166eeaf01e473b0bf185e85cf15ea4595c869897b3851b sh -c "cat /etc/*release | grep ^ID"
2025-09-23T19:51:01.1598277Z /__e/node20/bin/node: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.27' not found (required by /__e/node20/bin/node)
2025-09-23T19:51:01.1601034Z /__e/node20/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /__e/node20/bin/node)
2025-09-23T19:51:01.1601897Z /__e/node20/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by /__e/node20/bin/node)

https://github.com/yuji-hatakeyama/Furl/actions/runs/17957388349/job/51072107739

5.26 で解消することが確認できたたため '5.14' => '5.26' に変更しました。
https://github.com/yuji-hatakeyama/Furl/actions/runs/17957825083/job/51073646548

比較的新しいDebian などのイメージ (buster 以降なら問題ないと思われる) に、自分で perl 5.14 をインストールするように変更すれば解消する可能があると思います。
調査および対応したほうが望ましければ、別で行いたいと考えていますのでご連絡ください。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perl/docker-perl#100

こちら -buster を versionの後ろに付ければ解消されるはずなのでそちらを試していただけないでしょうか ?

Copy link
Contributor Author

@yuji-hatakeyama yuji-hatakeyama Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syohex san
ご確認ありがとうございます。 Buster の build 済みの image が存在したんですね 😅

使用したところ正常のテストが実施できました。
https://github.com/yuji-hatakeyama/Furl/actions/runs/17966814895/job/51100904420

3f8bce9 で修正しました。

@syohex syohex merged commit 4d94f4f into tokuhirom:master Sep 24, 2025
4 checks passed
syohex added a commit that referenced this pull request Sep 25, 2025
Changelog diff is:

diff --git a/Changes b/Changes
index 81a6724..aa0adb1 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,10 @@ Revision history for Perl module Furl
 
 {{$NEXT}}
 
+3.15 2025-09-25T00:24:03Z
+    - Fix the issue that when timeout happens, then request method returns success when
+      there is no Content-Length headers(#137)
+
 3.14 2021-05-13T05:30:22Z
     - Support 308 HTTP status code
@syohex
Copy link
Collaborator

syohex commented Sep 25, 2025

Thanks. I've release new version https://metacpan.org/release/SYOHEX/Furl-3.15

@yuji-hatakeyama
Copy link
Contributor Author

Thank you for the quick review and release! I really appreciate your prompt response.

@yuji-hatakeyama yuji-hatakeyama deleted the fix_body_timeout_no_content_length branch September 25, 2025 01:58
@yuji-hatakeyama yuji-hatakeyama restored the fix_body_timeout_no_content_length branch November 18, 2025 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants