corboy
V2EX  ›  问与答

PHP 连 MongoDB 报 ConnectionTimeoutException,大家有遇到过吗

  •  
  •   corboy · Apr 21, 2017 · 1098 views
    This topic created in 3331 days ago, the information mentioned may be changed or developed.

    Caused by: MongoDB\Driver\Exception\ConnectionTimeoutException

    No suitable servers found (serverSelectionTryOnce set): [connection refused calling ismaster on '10.0.80.16:27017']

    现象:

    • MongoDB 重启后, fpm 第一次连接 mongo 之后,出现以上异常。接下来该 fpm 进程再次连接正常。
    • MongoDB 重启, fpm 也跟着重启,则连接正常。

    个人推断: 一个 fpm 进程如果成功连接过 MongoDB ,当 MongoDB 重启后,该 fpm 再次连接 MongoDB 时,会报以上异常。

    1 replies    2017-04-21 19:53:14 +08:00
    billlee
        1
    billlee  
       Apr 21, 2017
    It's by design.
    MongoDB 的各种 client driver 都是保持持久连接的,连接异常断开后,就会抛出异常。
    你可以根据需要,捕获这个异常重试,或者忽略,让客户端重试。
    除了重启, replication set 切换 master 时也会抛出这个异常。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1047 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 18:39 · PVG 02:39 · LAX 11:39 · JFK 14:39
    ♥ Do have faith in what you're doing.