gpt4 book ai didi

perl - 如何捕获 Perl MongoDB::Cursor 的 'recv timed out' 错误?

转载 作者:可可西里 更新时间:2023-11-01 09:46:02 25 4
gpt4 key购买 nike

我有一个 Perl 程序通过 cron 发出这些消息:

recv timed out (60000 ms) at /usr/local/lib/perl/5.8.8/MongoDB/Cursor.pm line 251.
recv timed out (60000 ms) at /usr/local/lib/perl/5.8.8/MongoDB/Cursor.pm line 251.
recv timed out (60000 ms) at /usr/local/lib/perl/5.8.8/MongoDB/Cursor.pm line 251.

我已采取以下步骤来缓解:

  • $collection->find(...) 周围的 eval block
  • $cursor->next() 周围的 eval block
  • 连接 query_timeout 值 60000
  • 连接超时 1000

    超时并不奇怪,因为服务器负载很高。但我想巧妙地捕获超时并优雅地退出。

    有什么建议吗?

    更新:

    我确定 recv 超时肯定发生在 $cursor->next() 调用上。

    # doesn't capture
    {
    local $SIG{__DIE__} = sub { return; };
    $doc_ref = $cursor->next();
    };

    # doesn't capture
    eval { $doc_ref = $cursor->next(); };
  • 最佳答案

    它可能是调用 exit,而不是 diie,因此 eval 无法捕获它。试试 Test::Trap。

    Primarily (but not exclusively) for use in test scripts: A block eval on steroids, configurable and extensible, but by default trapping (Perl) STDOUT, STDERR, warnings, exceptions, would-be exit codes, and return values from boxed blocks of test code.

      use Test::Trap;

    my @r = trap { some_code(@some_parameters) };
    if ( $trap->exit != 0 ){
    say 'Expecting &some_code to exit with not 0';
    }

    关于perl - 如何捕获 Perl MongoDB::Cursor 的 'recv timed out' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13715246/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com