Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

timeout isn't working

オープン
#48 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
nodejs, typescript
領域
api, backend

調査の方向性

request-light の xhr エントリポイントから開始し、timeout オプションが Node.js リクエストにどのように適用されるかを追跡します。Issue にある動作する https の例と挙動を比較します。完了条件は、timeout: 1000 を指定したリクエストが完全なレスポンスを待つのではなく、reject または abort されることです。

索引モデルが issue の本文から書いたものです。

説明

AFAIK calling request.setTimeout(ms) does not automatically abort or fail the request when the timeout is reached. Instead, it simply emits a 'timeout' event on the request object where we would need to abort the request manually.

There isn't any logic in node-request-light capturing the timeout event so it will never timeout..

Recreation script (where 'request-light' is present in the node_modules folder):

const { xhr } = require('request-light');

async function testTimeout() {
  const timeoutMs = 1000;

  // This URL will wait for 10 seconds before responding
  const url = 'https://httpbin.org/delay/10';

  console.log(`Starting request to ${url} with a ${timeoutMs}ms timeout...`);
  const start = Date.now();

  try {
    const response = await xhr({
      url,
      timeout: timeoutMs
    });
    console.log(`Request finished successfully after ${Date.now() - start}ms (Status: ${response.status})`);
  } catch (error) {
    const duration = Date.now() - start;
    console.log(`Request failed after ${duration}ms`);
    if (error.status === 408 || error.message?.includes('timeout') || duration < 2000) {
      console.log('SUCCESS: The timeout was respected.');
    } else {
      console.log('FAILURE: The timeout was NOT respected. It likely waited for the full response.');
    }
    console.log('Error details:', error);
  }
}

testTimeout();

working nodejs example

const https = require('https');

function testWorkingTimeout() {
  const timeoutMs = 1000;
  const url = 'https://httpbin.org/delay/10';

  console.log(`Starting Node.js native request to ${url} with a ${timeoutMs}ms timeout...`);
  const start = Date.now();

  const req = https.get(url, (res) => {
    console.log('This should not be reached if timeout works.');
  });

  // Set the timeout
  req.setTimeout(timeoutMs);

  // Listen for the 'timeout' event (This is what request-light is missing)
  req.on('timeout', () => {
    console.log(`[TIMEOUT EVENT] Triggered after ${Date.now() - start}ms. Manually destroying the request...`);
    req.destroy(new Error('ETIMEDOUT')); 
  });

  req.on('error', (err) => {
    console.log(`[ERROR EVENT] Request failed as expected: ${err.message}`);
    console.log(`Total duration: ${Date.now() - start}ms`);
    
    if (Date.now() - start < 2000) {
        console.log('SUCCESS: The timeout was respected because we handled the event.');
    }
  });
}

testWorkingTimeout();
主要言語
TypeScript
スター
35
フォーク
22
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/node-request-light のほかの issue

microsoft/node-request-light の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。